Where - Type 1 - Example
string[] presidents = { "Adams",
"Arthur",
"Buchanan",
"Bush",};
IEnumerable<string> sequence = presidents.Where(p => p.StartsWith("A"));
foreach (var item in sequence)
Console.WriteLine(item);
//Output
Adams
Arthur
"Arthur",
"Buchanan",
"Bush",};
IEnumerable<string> sequence = presidents.Where(p => p.StartsWith("A"));
foreach (var item in sequence)
Console.WriteLine(item);
//Output
Adams
Arthur
Where - Type 2 with index - Example
string[] presidents = { "Adams", // index 0
"Arthur", // index 1
"Buchanan",// index 2
"Bush",}; // index 3
IEnumerable<string> sequence = presidents.Where((p,i) => i>2); //i is the index of the element
foreach (var item in sequence)
Console.WriteLine(item);
//Output
Bush
"Arthur", // index 1
"Buchanan",// index 2
"Bush",}; // index 3
IEnumerable<string> sequence = presidents.Where((p,i) => i>2); //i is the index of the element
foreach (var item in sequence)
Console.WriteLine(item);
//Output
Bush
No comments:
Post a Comment