2022-10-03 761 0
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace Linq控制台
{
class Program
{
static void Main(string[] args)
{
List<student> student = new List<student> { };
List<scores> scroes = new List<scores> { };
var list = from stu in student
join scr in scroes on stu.ID equals scr.ID
where (scr.Chinese + scr.Math) / 2 > 60
group stu by new { stu.Age } into TableE
orderby TableE.Key.Age descending
select new{ Age = TableE.Key.Age, qty = TableE.Count() };
List<int> num = new List<int>() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
var quer1 = from x in num
where x > 3
group x by x % 2;//只能以select或group by结尾
var quer2 = from x in num
where x > 3
group x by x % 2 into T //into放进一个临时表
from y in T
select y;
string[] lan = { "C", "C++", "VB", "VC", "C#", "GO", "PYTHON", "JAVA", "VB.NET", "PERL", "DELPHI", "KYLIX" };
var quer3 = from x in lan
group x by x.Length into T
orderby T.Key ascending//T.Key协变量
select T;
int[] a = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int[] b = new int[] { 0, 1, 2, 3, 4 };
var quer4 = from x in a
join y in b on x equals y//这里的相等要用equals
where x < 3 && y % 2 == 0
select x;//select y也可以
var quer5 = from x in a
join y in b on x equals y into T//INTO 可以接在group和Join后面
select T;
Console.WriteLine("Print:");
foreach (var item in quer5)
{
foreach (var u in item)
{
Console.WriteLine(u);
}
}
Console.ReadLine();
}
}
class student { public string ID; public int Age; }
class scores { public string ID; public int Chinese, Math; }
}