普段はC#でしかLINQ書かないので、細かい書き方はちょっと怪しいですが…。
むりやりワンライナーで書くならこんな感じでしょうか。
vb.net
1details.TakeWhile(Function(d) Not String.IsNullOrEmpty(d.Code)).
2 Select(Function(d, i) New With {Key .Detail = d, Key .GrpIdx = i \ 10}).
3 GroupBy(Function(a) a.GrpIdx).
4 Select(Function(g) String.Join(",", g.Select(Function(a) a.Detail.Code))).
5 ToList().
6 ForEach(Sub(l) logger.Info(l))
- 最初のTakeWhileは、ご提示いただいたコードのとおりWhereでも構いませんが、
空白があった時点でそれ以降の要素を見る必要がないならばTakeWhileのほうが意図がわかりやすいと思います。
もう少し読みやすくなるかもしれません。
vb.net
1Public Module IEnumerableExt
2
3 <Runtime.CompilerServices.Extension()>
4 Public Function ToGroupsOf(Of T)(collection As IEnumerable(Of T), count As Integer) As IEnumerable(Of IGrouping(Of Integer, T))
5 If collection Is Nothing Then
6 Throw New ArgumentNullException("collection")
7 End If
8 If count <= 0 Then
9 Throw New ArgumentOutOfRangeException("count")
10 End If
11
12 Return collection.Select(Function(x, i) New With {Key .Val = x, Key .GrpIdx = i \ count}).
13 GroupBy(Function(a) a.GrpIdx, Function(a) a.Val)
14 End Function
15End Module
vb.net
1details.TakeWhile(Function(d) Not String.IsNullOrEmpty(d.Code)).
2 ToGroupsOf(10).
3 Select(Function(g) String.Join(",", g.Select(Function(d) d.Code))).
4 ToList().
5 ForEach(Sub(l) logger.Info(l))
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。