var students = new[]
{
new {id=1,name="张三"},
new {id=2,name="李四"},
};
var scores = new[]
{
new{id=2,mark=79} };
var result = from student in students join score in scores on student.id equals score.id into stuscores from stuscore in stuscores.DefaultIfEmpty()
select new
{
student.name,
mark = (stuscore == null ? null : (int?)stuscore.mark)
};
foreach (var r in result)
{
Console.WriteLine("姓名:"+r.name+",成绩:"+r.mark);
}