If you find this article useful, consider making a small donation to show your support for this web site and its content.
DiscountASP
AboutMe
About me:
Hi. My name is Farooq Kaiser and I'm a software developer from Toronto, Canada.

LINQ querying generic list

by Farooq Kaiser 3. February 2009 05:04

I will compose a query to retrieve all the items in a generic List.

    public class Customer

        {
            public int Id;
            public string Name;
 
            public Customer(int id, string name)
            {
                this.Id = id;
                this.Name = name;
            }
        }
 
List<Customer> cust = new List<Customer>();
 
cust.Add(new Customer(1008, "Microsoft"));
cust.Add(new Customer(999, "Google"));
cust.Add(new Customer(879, "Yahoo"));
cust.Add(new Customer(1206, "Amazon"));
 
  var names = from p in cust select new {CompanyName=p.Name};
      foreach(var name in names)
        Console.WriteLine(name.CompanyName);
 


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

.NET | C#

Jobs Autos Real estate Videos Power by Google