Collection of Values using Lookup Collection
Lookup
is a collection of keys each mapped to one or more values, so here is the representation of the collection Lookup<TKey, TElement> .
Where TElement
is the new collection type of elements. The Code
static void Main(string[] args) { List<Customer> customer = new List<Customer>() { new Customer{ ID=1,Name="Bhaumik",Status=true}, new Customer{ ID=1,Name="Hardik",Status=true}, new Customer{ ID=1,Name="Rachit",Status=false}, new Customer{ ID=1,Name="Darshan",Status=true}, new Customer{ ID=1,Name="Manan",Status=false}, new Customer{ ID=1,Name="Malay",Status=true}, new Customer{ ID=1,Name="Vishal",Status=false}, new Customer{ ID=1,Name="Raj",Status=true}, new Customer{ ID=1,Name="Rohit",Status=false} }; Lookup<bool, Customer> customerLookup = (Lookup<bool, Customer>)customer.ToLookup(cust => cust.Status); Console.WriteLine("Customer whith Status = true"); foreach (Customer cust in customerLookup[true]) { Console.WriteLine("Mr. {0} ==> Status {1}", cust.Name, cust.Status); } Console.WriteLine("Customer whith Status = false"); foreach (Customer cust in customerLookup[false]) { Console.WriteLine("Mr. {0} ==> Status {1}", cust.Name, cust.Status); } Console.ReadKey(true); }Customer.cs
class Customer { public int ID { get; set; } public string Name { get; set; } public bool Status { get; set; } }The Output
Collection of Values using Lookup Collection
Reviewed by Bhaumik Patel
on
3:20 AM
Rating: