LINQ 獲取當前數組中出現次數最多的元素

			int[] comparValue = { 11, 22, 11, 11, 33, 11, 22 };
			var query = (from num in
							(
							from number in comparValue
							group number by number into g
							select new
							{
								number = g.Key,
								cnt = g.Count()
							}
						)
						orderby num.cnt descending
						select num.number).First();
			Console.WriteLine("{0}", query);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章