//重复元素:3,4,5 //不重复元素:1,8,9 int[] arr = { 1, 3, 3, 3, 4, 5, 4, 5, 8, 9, 3 }; //不重复元素 var unique = arr.GroupBy(i => i) .Where(g => g.Count() == 1) .Select(g => g.ElementAt(0)); foreach (var i in unique) Console.WriteLine(i); //分割线 Console.WriteLine("==="); //重复元素 var duplicate = arr.GroupBy(i => i) .Where(g => g.Count() > 1) .Select(g => g.ElementAt(0)); foreach (var i in duplicate) Console.WriteLine(i);
输出: 1 8 9 === 3 4 5
linq OrderBy 方法 两个字段同时排序有关问题
linq OrderBy 方法 两个字段同时排序问题
OrderBy(c => c.name )再加一个字段倒序排怎么写。 OrderBy(c => c.shipper_name ).OrderByDescending(c => c.Time) 这样写结果是不对的。。请教该怎么写
var values = from u in users where u.ID < 6 orderby u.Username descending,u.ID ascending select u;
比如在SQL中:select a1,a2,a3 from t1 order by a1 desc ,a2 asc
在LINQ中
source = from t in db.t1
select new TModel {
A1=a1;
A2=a2;
A2=a3;
};
ordered = source.OrderByDescending(t => new { t.a1 }).ThenBy(t => new { t.a2 });
如果都是按升序排,可以orderby(p=>p.date).thenby(p=>p.id)
sql 多字段排序:http://www.cnblogs.com/shy1766IT/p/5272267.html
https://www.mgenware.com/blog/?p=133 .NET(C#):LINQ找出重复和不重复的元素