LINQ Query Syntax
class person
{
public string FirstName { get; set;}
public string LastName { get; set; }
public int Age { get; set;}
}
class alternateperson
{
public string FullName { get; set; }
public int Age { get; set; }
}
class Program
{
static void Main(string[] args)
{
List<person> people = new List<person> { new person{FirstName = "Venu", LastName = "Pavuluri", Age = 28},
new person{FirstName = "Babu", LastName = "Pav", Age = 30},
new person{FirstName = "Victor", LastName = "Serbin", Age = 35}
};
IEnumerable<alternateperson> results = from p in people
select new alternateperson {FullName = p.FirstName + " " + p.LastName, Age = p.Age};
/*people.Select(p => new alternateperson
{
FullName = p.FirstName + " " + p.LastName,
Age = p.Age
});
*/
foreach(var r in results)
Console.WriteLine("Full Name: {0}, \nAge: {1}\n",r.FullName, r.Age);
}
}
{
FullName = p.FirstName + " " + p.LastName,
Age = p.Age
});
Comments