Sorting Data using LINQ

Posted by Prabhukiran345 under LINQ category on | Points: 40 | Views : 501
Let us consider some Static Data:
ArrayList names = new ArrayList(5);
names.Add("Tony Abbot");
names.Add("Tony A Farrow");
names.Add("Tony Charles");
names.Add("Tony Small");
names.Add("Bob Brown");

Now the LinQ query for sorting data is:
var query = from p in names.Cast<string>()
let count = p.Split(' ').Length - 1
let surname = p.Split(' ')[count]
let givenname = p.Split(' ')[0]
orderby surname ascending
select new
GivenName = givenname,
Surname = surname

This returns Data in Ascending Order..

Comments or Responses

Login to post response