Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个包含 3000 个单词的字符串数组。如何使用 LINQ 将数组分成十组。每十个项目应存储在一个变量中。结果应该是一个包含组的新数组。
假设单词由单个空格分隔,您可以像这样拆分和重新分组:
var res = longWord .Split(' '). .Select((s, i) => new { Str = s, Index = i }) .GroupBy(p => p.Index / 10) .Select(g => string.Join(" ", g.Select(v => v.Str)));