Mega Code Archive

 
Categories / C# Book / 04 LINQ
 

0386 Anonymous Types

Anonymous types allow you to create the intermediate results without writing classes. using System; using System.Collections; using System.Collections.Generic; using System.Linq; class Program { static void Main() { string[] names = { "Java", "C#", "Javascript" }; var intermediate = from n in names select new { item1 = n, item2 = n.Replace("a", "").Replace("e", "").Replace("i", "") .Replace("o", "").Replace("u", "") }; IEnumerable<string> query = from item in intermediate where item.item1.Length > 2 select item.item2; foreach(string s in query){ Console.WriteLine(s); } } } The output: Jv Jvscrpt