/ Published in: C#
This is a simple Linq query against a list of Star Wars characters.
Expand |
Embed | Plain Text
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)); } } }
Comments
Subscribe to comments
You need to login to post a comment.

Works, but would have been better if CharacterType was an enum.
Amen to that brother! I want to rid the world of magic strings too. Thanks for the feedback.