猿问

OrderBy方法如何实现多字段排序?

var employee = new[]{ 
                new{id="2", name="name3"},
                new{id="1",name="name4"},
                new{id="3",name="name2"},
                new{id="1",name="name1"}
            };

            foreach (var emp in employee.OrderBy(c => c.id))
            {
                Console.WriteLine("id:{0} name:{1}", emp.id, emp.name);
            }

请问OrderBy如何实现对id和name同时进行排序(像order by id asc,name asc一样)?


拉风的咖菲猫
浏览 246回答 2
2回答

一只甜甜圈

foreach (var emp in employee.OrderBy(c => c.id)&&………………)应该可以!!!
随时随地看视频慕课网APP
我要回答