LINQ With OrderBy To Sorting CompanyName And OrderNumber
using System;
using System.Linq;
class Company
{
public string CompanyName{get;set;}
public int OrderNumber {get;set;}
}
class OrderByWithLINQ
{
static void Main()
{
Company[] cmparr = {
new Company{CompanyName="W3Schools", OrderNumber=6798},
new Company{CompanyName="ABC Shop", OrderNumber=5678},
new Company{CompanyName="Sega", OrderNumber=3412},
new Company{CompanyName="W3Schools", OrderNumber=2312}
};
var result = from r in cmparr
select r;
Console.WriteLine("==================================================");
Console.WriteLine("Output without orderby on CompanyName and OrderNumber");
Console.WriteLine("==================================================");
foreach(var r in result)
Console.WriteLine("Company Name is {0} and OrderNumber is {1}",r.CompanyName, r.OrderNumber);
var result1 = from r in cmparr
orderby r.CompanyName, r.OrderNumber
select r;
Console.WriteLine("==================================================");
Console.WriteLine("Output with orderby on CompanyName and OrderNumber");
Console.WriteLine("==================================================");
foreach(var r in result1)
Console.WriteLine("Company Name is {0} and OrderNumber is {1}",r.CompanyName, r.OrderNumber);
}
}
OUTPUT
LINQ With OrderBy To Sorting CompanyName And OrderNumber
Reviewed by Baljeet Singh
on
12:50
Rating:
No comments: