{"id":28910595,"url":"https://github.com/x-stars/rangeforeach","last_synced_at":"2026-02-25T08:04:33.345Z","repository":{"id":41520197,"uuid":"510037347","full_name":"x-stars/RangeForeach","owner":"x-stars","description":"C# range-foreach syntax provider.","archived":false,"fork":false,"pushed_at":"2025-04-25T14:33:40.000Z","size":83,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-21T18:14:20.284Z","etag":null,"topics":["csharp","foreach","range","syntax"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/RangeForeach.Sources","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/x-stars.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-03T13:53:29.000Z","updated_at":"2025-04-25T14:33:39.000Z","dependencies_parsed_at":"2024-02-07T12:34:00.028Z","dependency_job_id":"2f1f46db-f190-40bc-a3db-4f6fd40cdbcc","html_url":"https://github.com/x-stars/RangeForeach","commit_stats":{"total_commits":56,"total_committers":1,"mean_commits":56.0,"dds":0.0,"last_synced_commit":"36b2c7db9bcd14dc5a2d1f5596ca3267f9d0b065"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/x-stars/RangeForeach","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x-stars%2FRangeForeach","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x-stars%2FRangeForeach/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x-stars%2FRangeForeach/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x-stars%2FRangeForeach/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/x-stars","download_url":"https://codeload.github.com/x-stars/RangeForeach/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x-stars%2FRangeForeach/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261170570,"owners_count":23119520,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","foreach","range","syntax"],"created_at":"2025-06-21T18:14:20.452Z","updated_at":"2026-02-25T08:04:33.340Z","avatar_url":"https://github.com/x-stars.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# C# Range-Foreach Syntax Extensions\n\nProvides the range-foreach syntax for **C# 9.0 or higher**.\n\nSupported frameworks:\n\n* .NET Framework \u003e= 3.5\n* .NET Core \u003e= 1.0\n* .NET Standard \u003e= 1.0\n\n## Range-Foreach Syntax\n\nReference source files or the NuGet package to write foreach loops like this:\n\n``` csharp\nforeach (var index in 0..100)\n{\n    // loop body...\n}\n```\n\nwhich is equivalent to the legacy for loop below:\n\n``` csharp\nfor (int index = 0; index \u003c 100; index++)\n{\n    // loop body...\n}\n```\n\n**TIPS:** `0` can be omitted in range expressions, e.g. `..100` (equivalent to `0..100`).\n\n**NOTE:** Use `^` to represent negative numbers, e.g. `^100..0` (instead of `-100..0`).\n\n### Stepped Syntax\n\nUse the `Step` method to write foreach loops like this:\n\n``` csharp\nforeach (var index in (99..^1).Step(-2))\n{\n    // loop body...\n}\n```\n\nwhich is equivalent to the legacy for loop below:\n\n``` csharp\nfor (int index = 99; index \u003e -1; index -= 2)\n{\n    // loop body...\n}\n```\n\n## Dependency Type Polyfill\n\nThis syntax requires the `System.Range` type (and also the `System.Index` type).\nConsidering that early frameworks do not provide this type, this project includes the polyfill source.\n\nIf a third party package that includes the `System.Range` type (such as `IndexRange`, etc.) is referenced,\ndefine the `INDEX_RANGE_EXTERNAL` constant in the project file to avoid duplicate definitions:\n\n``` xml\n\u003cDefineConstants\u003e$(DefineConstants);INDEX_RANGE_EXTERNAL\u003c/DefineConstants\u003e\n```\n\n## Performance Benchmark\n\n``` plaintext\nBenchmarkDotNet v0.13.10, Windows 11 (10.0.22631.2792/23H2/2023Update/SunValley3)\nAMD Ryzen 7 5800H with Radeon Graphics, 1 CPU, 16 logical and 8 physical cores\n.NET SDK 8.0.100\n  [Host]     : .NET 8.0.0 (8.0.23.53103), X64 RyuJIT AVX2\n  DefaultJob : .NET 8.0.0 (8.0.23.53103), X64 RyuJIT AVX2\n```\n\n|                   Method | LoopCount | Mean        | StdDev    | Ratio | Code Size |\n|------------------------- |----------:|------------:|----------:|------:|----------:|\n|             `CounterFor` |         1 |   0.0037 ns | 0.0032 ns |     ? |      20 B |\n|           `RangeForeach` |         1 |   0.0026 ns | 0.0010 ns |     ? |      39 B |\n|    `SteppedRangeForeach` |         1 |   0.0051 ns | 0.0022 ns |     ? |      39 B |\n| `EnumerableRangeForeach` |         1 |   7.2937 ns | 0.1077 ns |     ? |     593 B |\n|                          |           |             |           |       |           |\n|             `CounterFor` |         3 |   0.4622 ns | 0.0033 ns |  1.00 |      20 B |\n|           `RangeForeach` |         3 |   0.4623 ns | 0.0011 ns |  1.00 |      39 B |\n|    `SteppedRangeForeach` |         3 |   0.4639 ns | 0.0034 ns |  1.00 |      39 B |\n| `EnumerableRangeForeach` |         3 |   9.4142 ns | 0.1430 ns | 20.37 |     644 B |\n|                          |           |             |           |       |           |\n|             `CounterFor` |        10 |   2.1077 ns | 0.0098 ns |  1.00 |      20 B |\n|           `RangeForeach` |        10 |   2.1039 ns | 0.0019 ns |  1.00 |      39 B |\n|    `SteppedRangeForeach` |        10 |   2.1064 ns | 0.0055 ns |  1.00 |      39 B |\n| `EnumerableRangeForeach` |        10 |  14.0306 ns | 0.0623 ns |  6.66 |     644 B |\n|                          |           |             |           |       |           |\n|             `CounterFor` |       100 |  26.3959 ns | 0.0289 ns |  1.00 |      20 B |\n|           `RangeForeach` |       100 |  27.8959 ns | 0.0137 ns |  1.06 |      39 B |\n|    `SteppedRangeForeach` |       100 |  27.9739 ns | 0.0267 ns |  1.06 |      39 B |\n| `EnumerableRangeForeach` |       100 |  64.2927 ns | 0.4154 ns |  2.44 |     644 B |\n|                          |           |             |           |       |           |\n|             `CounterFor` |      1000 | 230.8943 ns | 0.1496 ns |  1.00 |      20 B |\n|           `RangeForeach` |      1000 | 235.6411 ns | 0.1965 ns |  1.02 |      39 B |\n|    `SteppedRangeForeach` |      1000 | 235.9903 ns | 0.3364 ns |  1.02 |      39 B |\n| `EnumerableRangeForeach` |      1000 | 513.7996 ns | 1.7926 ns |  2.23 |     644 B |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fx-stars%2Frangeforeach","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fx-stars%2Frangeforeach","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fx-stars%2Frangeforeach/lists"}