h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

LINQ To Object --Example -2

Today, we will see how to use Order class in LINQ.

Create a One Class Called : ClsEmployee
Three Properties in the Class.


1)EmpId2)Name3)Salary
public string Name { get; set; } public string EmpID { get; set; } public int Salary { get; set; }
Create a One form
Drag and Drop one Button.
Button name is btn_Result.
Create a Method:
Method name is "InsertintoTable()
List objEmployee = new List { new ClsEmployees { EmpID = "1001" ,Name ="GANTEC", Salary =10000 }, new ClsEmployees { EmpID = "1002" ,Name ="IBM", Salary =15000 }, new ClsEmployees { EmpID = "1003" ,Name ="CTS", Salary =20000 }, new ClsEmployees { EmpID = "1004" ,Name ="WIPRO", Salary =30000 }, new ClsEmployees { EmpID = "1005" ,Name ="SATHYAM", Salary =40000 }, new ClsEmployees { EmpID = "1006" ,Name ="BUTTERFLY", Salary =50000 }, new ClsEmployees { EmpID = "1007" ,Name ="CON", Salary =10000 }, new ClsEmployees { EmpID = "1008" ,Name ="TVS", Salary =75000 }, new ClsEmployees { EmpID = "1010" ,Name ="TATA", Salary =90000 }, new ClsEmployees { EmpID = "1009 " ,Name ="GANTEC COR", Salary =100000 }, };
Call this method in button Click Event and Add below codes,
var OrderBy = (from emp in objEmployee select emp).OrderBy(x => x.Name);

Happy Coding!!!