linq select query simple
Select - Simple 1
Select - Simple 2
Select - Transformation
static void Select_1_Simple() { int[] numbers = { 2, 3, 1, 4, 7, 8, 6, 5, 0, 9 }; var numsPlusOne = from n in numbers select n + 1; Console.WriteLine("Numbers + 1:"); foreach (var i in numsPlusOne) { Console.WriteLine(i); } Console.ReadKey(true); }Output
Select - Simple 2
static void Select_2_Simple() { List<Customer> customer = new List<Customer>() { new Customer{ ID=1,Name="Bhaumik",Status=true}, new Customer{ ID=2,Name="Hardik",Status=true}, new Customer{ ID=3,Name="Rachit",Status=false}, new Customer{ ID=4,Name="Darshan",Status=true}, new Customer{ ID=5,Name="Manan",Status=false}, new Customer{ ID=6,Name="Malay",Status=true}, new Customer{ ID=7,Name="Vishal",Status=false}, new Customer{ ID=8,Name="Raj",Status=true}, new Customer{ ID=9,Name="Rohit",Status=false} }; var productNames = from p in customer select p.Name; Console.WriteLine("Customer Names:"); foreach (var productName in productNames) { Console.WriteLine(productName); } Console.ReadKey(true); }Output
Select - Transformation
static void Select_Transformation() { int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; string[] strings = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; var textNums = from n in numbers select strings[n]; Console.WriteLine("Number strings:"); foreach (var s in textNums) { Console.WriteLine(s); } }Output
linq select query simple
Reviewed by Bhaumik Patel
on
11:15 PM
Rating: