在运行时声明对象数组大小的VB.NET语法是什么?
要了解我的意思,这里是到目前为止的代码:
Private PipeServerThread As Thread()
Public Sub StartPipeServer(NumberOfThreads As Integer)
' ??? equivalent of C#
' ??? PipeServerThread = new Thread[numberOfThreads];
' ??? goes here
For i = 0 To NumberOfThreads - 1
PipeServerThread(i) = New Thread(New ThreadStart(AddressOf ListeningThread))
PipeServerThread(i).Start()
Next i
End Sub
我已经尝试了几件事,但最终将其与对象创建语法相混淆。
最佳答案
PipeServerThread = New Thread(numberOfThreads - 1) { }
或者:
ReDim PipeServerThread(numberOfThreads - 1)
请记住,括号内的值是VB.NET中数组的上限(与C#的数组长度不同)。