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()
- {
- List<string> heroes = new List<string> { "D. Va", "Lucio", "Mercy", "Soldier 76", "Pharah", "Reinhardt" };
- //var is an implicitly typed variable — we let the C# compiler determine the actual type for us.
- var shortHeroes = from h in heroes
- where h.Length < 8
- select h;
- //print those of length shorter than 8 characters from the list
- foreach (string hero in shortHeroes){
- Console.WriteLine(hero);
- }
- var longHeroes = heroes.Where(n => n.Length >8);
- Console.WriteLine(longHeroes.Count());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement