/ Published in: C#
This is a simple Linq query against a list of Star Wars characters.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
using System; using System.Collections.Generic; using System.Linq; namespace ExampleLinq { public class StarWarsCharacter { public string Name { get; set; } public CharacterType CharacterType { get; set; } } public enum CharacterType { Hero, Villain } public class Program { static void Main(string[] args) { { }; var heroes = from s in starWarsCharacters where s.CharacterType == CharacterType.Hero select s.Name; heroes.ToList<string>().ForEach(h => Console.WriteLine(h)); } } }