using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AdvancedLinq
{
class LinqTest
{
public void Show()
{
List
{
new Student
{
Id=1,
Name = "Ant编程",
Age = 1,
Address = "西安"
},
new Student
{
Id=2,
Name = "Ant编程2",
Age = 20,
Address = "西安"
},
new Student
{
Id=3,
Name = "Ant编程3",
Age = 30,
Address = "西安"
}
};
{
Console.WriteLine("普通查询");
foreach (var item in stuList)
{
if (item.Age <= 20)
{
Console.WriteLine("id" + item.Id, "Name" + item.Name);
}
}
}
{
Console.WriteLine("linq方式");
var list = stuList.Where(s => s.Age <= 20);
foreach (var item in list)
{
Console.WriteLine(item.Name, item.Age);
}
foreach (var item in stuList.OrderByDescending(x => x.Age))
{
Console.WriteLine(item.Id);
}
}
{
}
}
}
}