Last active
June 8, 2020 07:28
-
-
Save SchlenkR/e5020fbeda5a68d93994bdd048deb9df to your computer and use it in GitHub Desktop.
What "SelectMany", "For statements" and "from / for expressions" have in common
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var l1 = new[] | |
{ | |
new | |
{ | |
name = "Jana", | |
projects = new[] {"p1", "p3"} | |
}, | |
new | |
{ | |
name = "Ronald", | |
projects = new[] {"p1", "p2"} | |
}, | |
}; | |
var res1 = l1 | |
.SelectMany(person => person.projects | |
.SelectMany(project => project.ToCharArray()) | |
.Select(char.ToUpperInvariant)) | |
.ToList(); | |
var res2 = new List<char>(); | |
foreach (var person in l1) | |
foreach (var project in person.projects) | |
foreach (var c in project.ToCharArray().Select(char.ToUpperInvariant)) | |
res2.Add(c); | |
var res3 = | |
from person in l1 | |
from project in person.projects | |
from c in project.ToCharArray().Select(char.ToUpperInvariant) | |
select c; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment