dotnet / csharplang

The official repo for the design of the C# programming language
10.95k stars 999 forks source link

Feature Request: Recursively Foreach #8015

Closed wisamidris7 closed 2 months ago

wisamidris7 commented 2 months ago

I know this is looks crazy idea but it will be very good for c# cause in dart now it contains recursively foreach So can c# have recursively foreach to make it very easy

It could be like this

foreach (var item in Items; var level = 0; var children = item.Children)
{
     Console.WriteLine("We are in level " + level);
     Console.WriteLine("We are in item" + item.Name);
     Console.WriteLine("We are in my children count" + children?.Count() ?? 0);
}

This is the best thing i think with if you can make a different or easier one it's okay but that what i think will be awesome