在《LINQ Cookbook》的第5个条目(拼接CheckedListBox中选中的字符串)中,微软公司Visual Basic团队演示了分别使用两种VB 9中的新特性来实现这类字符串连接的方法。
\在第一种方法里,Visual Basic团队使用了LINQ的聚合(Aggregate)语法。如下述代码所示,将各个字符串用逗号连接起来:
\MsgBox( _
\tAggregate Box In CheckedListBox1.CheckedItems _
\tInto Concat())
代码中的Concat是一个扩展方法(extension method),其实现如下:
\Public Module AggregateModule
\tPublic Function Concat(Of Type)( _
\t\tByVal ie As IEnumerable(Of Type)) As String
\t\tDim str As String = \"\"
\t\tFor Each item In ie
\t\t\tIf str \u0026lt;\u0026gt; \"\" Then str \u0026amp;= \