linq查询的输出 - > System.Linq.Lookup`2 + Grouping [System.Int32,System.Int32](Output of a linq query --> System.Linq.Lookup`2+Grouping[System.Int32,System.Int32])
我想要一个奇数出现的数组的数量。
这是我的代码。 我认为它正在工作,但我不能输出预期的数字2作为字符串。 我有
System.Linq.Lookup`2+Grouping[System.Int32,System.Int32]代替。
int[] array = { 0, 0, 1, 1, 2 }; var result = array.GroupBy(a => a) .Select(o => o) .Where(o => (o.Count() % 2 == 1)) .FirstOrDefault(); Console.WriteLine(result.ToString());I want the number of an array with odd occurrences.
This is my code. I think it is working but I cannot output the expected number 2 as a string. I got
System.Linq.Lookup`2+Grouping[System.Int32,System.Int32]instead.
int[] array = { 0, 0, 1, 1, 2 }; var result = array.GroupBy(a => a) .Select(o => o) .Where(o => (o.Count() % 2 == 1)) .FirstOrDefault(); Console.WriteLine(result.ToString());最满意答案
尝试这个:
var result = array.GroupBy(a => a) .Where(o => o.Count() % 2 == 1) .FirstOrDefault().Key;Try this:
var result = array.GroupBy(a => a) .Where(o => o.Count() % 2 == 1) .FirstOrDefault().Key;更多推荐
发布评论