Create new T[] in VB.NET
How can I do the same as the following in VB.NET
List<T[]> result = new List<T[]>();
// single combination
if (k == 0)
{
result.Add(n开发者_运维技巧ew T[0]); // T is function type argument of generic function
How can I write the last line above in VB.NET?
I tried:
result.Add(New T(0)) 'doesn't work!
It should be:
result.Add(New T(0) {})
I tried the following:
Dim A(0) As T ' Length = 1
Dim B As T() = New T(0) {} ' Length = 1
Dim C As T() = New T() {} ' Length = 0
Dim D As T() = New T(-1) {} ' Length = 0
Dim E(-1) As T ' Length = 0
Dim F As T() = Array.CreateInstance(GetType(T), 0) ' Length = 0
So I recommend the 3rd option at it is the cleanest.
精彩评论