连接2个变量

时间:2015-07-02 03:06:55

标签: vb.net concatenation

如何使此代码正常工作?

Dim c As Integer = 0
For iCol = 0 To reader.FieldCount
    Dim col+c As String = reader.GetName(iCol))
    c = c + 1
Next

由于

3 个答案:

答案 0 :(得分:1)

您也可以使用List<String>

Dim lst as new List<String>();
For iCol = 0 To reader.FieldCount - 1
    lst.Add(reader.GetName(iCol));
Next

答案 1 :(得分:0)

Dim list as new List<String>(reader.FieldCount);
For iCol = 0 To reader.FieldCount - 1
    list.Add(reader.GetName(iCol));
Next

这是对所选答案的改进,因为它使用与字段数匹配的容量初始化列表。

请参阅https://msdn.microsoft.com/en-us/library/dw8e0z9z(v=vs.110).aspx

答案 2 :(得分:-1)

所以这是我的代码:

Dim growingArray() As String = Nothing
For iCol = 0 To reader.FieldCount - 1
    ReDim Preserve growingArray(iCol)
    growingArray(iCol) = reader.GetName(iCol)
Next

来源:http://www.java2s.com/Tutorial/VB/0160__Collections/UseReDimPreservetoaddelementstoanarray.htm

感谢SSS