using select operator in linq query

Observe that in the given query, the variable, in this case - query refers the type of IEnumerable <anonymous type>objects. These objects are of an anonymous type and contain CustomerId and Name.

SalesDBDataContext dataContext = new SalesDBDataContext();
var query = from c in dataContext.Customers
			select new { c.Name, c.Address };
foreach(var customer in query)
	{ 
    	Console.WriteLine(customer.Name + customer.Address );    
    }
Console.ReadLine();




To create an anonymous type, we use select operator with the new keyword. The Select operator projects CustomerId and Address fields of customer object. Note that we can also give a new name to the projected fields as shown below.

var query = from c in dataContext.Customers
			select new { CustomerName=c.Name, CustomerInfo=c.Address };