Gus*_*ren 0 c# linq excel ienumerable vsto
我有一个名为Sheet的类,其中包含一个包含Row对象的List .每个Row对象都有一个包含Cell对象的List .现在我想实现一个Sheet.Cells属性,该属性返回所有行上的所有单元格.我确信必须有一个优雅的LINQ解决方案,但一直无法弄清楚.假设我在this.rows中获得了所有行,如何使用LINQ获取包含所有行中所有单元格的IEnumerable?
IEnumerable<Cell> cells = this.rows ...?
Run Code Online (Sandbox Code Playgroud)
有,叫做SelectMany:
IEnumerable<Cell> cells = this.rows.SelectMany(r => r.Cells);
Run Code Online (Sandbox Code Playgroud)