CSharp examples for LINQ:Select
Select Multiple Member Values
using System;/*from w w w . jav a2s . c o m*/ using System.Collections.Generic; using System.Linq; using System.Text; class MainClass { static void Main(string[] args) { IList<Item> sourcedata = createData(); var result = from e in sourcedata select new { e.Name, e.Color }; foreach (var element in result) { Console.WriteLine("Result: {0} {1}", element.Name, element.Color); } // Wait to continue. Console.WriteLine("\nMain method complete. Press Enter"); Console.ReadLine(); } static IList<Item> createData() { return new List<Item>() { new Item("Oracle", "green", 7), new Item("MySQL", "MySQL", 10), new Item("C", "green", 4), new Item("fig", "brown", 12), new Item("C", "green", 4), new Item("HTML", "brown", 12), new Item("XML", "red", 2), new Item("Javascript", "green", 4), new Item("fig", "brown", 12), new Item("SQL", "red", 2), new Item("C", "green", 4), new Item("SVG", "brown", 12), new Item("XML", "red", 2), new Item("XML", "red", 2), new Item("file", "yellow", 10), new Item("PLSQL", "red", 7) }; } } class Item { public Item(string namearg, string colorarg, int lifearg) { Name = namearg; Color = colorarg; ShelfLife = lifearg; } public string Name { get; set; } public string Color { get; set; } public int ShelfLife { get; set; } }