linq 左连 右连

来源:互联网 发布:小米手环软件 编辑:程序博客网 时间:2024/04/29 10:52

var students = new[]

 {

new {id=1,name="张三"},

 new {id=2,name="李四"},

 };

var scores = new[]

 {

new{id=2,mark=79} };

 var result= from studentin studentsjoin score in scores on student.idequals score.idinto stuscoresfrom stuscorein stuscores.DefaultIfEmpty()

select new

 {

student.name,

mark = (stuscore== null? null : (int?)stuscore.mark)

 };

foreach (var rin result)

 {

Console.WriteLine("姓名:"+r.name+",成绩:"+r.mark);

 }

原创粉丝点击