Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace LearnLinq
- {
- class Program
- {
- static void Main()
- {
- string[] heroes = { "D. Va", "Lucio", "Mercy", "Soldier 76", "Pharah", "Reinhardt" };
- //Method syntax using separate statements
- var HeroesWithC = heroes.Where( h => h.Contains("c"));
- var lowerHeroesWithC = HeroesWithC.Select( h=> h.ToLower());
- //Method syntax using chain expressions
- var sameResult = heroes
- .Where(h => h.Contains("c"))
- .Select(h=> h.ToLower());
- //Both ways will print the same result
- foreach (string s in lowerHeroesWithC)
- {
- Console.WriteLine(s);
- }
- foreach (string s in sameResult)
- {
- Console.WriteLine(s);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement