我试图做这样的事情:
static void Main(string[] args)
{
string[] clients = new clients[0];
createClients(clients);
//do something with clients
}
static void CreateClients(string[] clients)
{
//ask how many clients
int c = Convert.ToInt32(Console.ReadLine());
clients = new string[c];
}
但是当我退出 CreateClients 过程时,'clients' 数组没有被修改,我是否遗漏了什么?我认为数组总是作为参考传递
谢谢
您需要通过引用传递客户端数组。
createClients(ref clients);
static void CreateClients(ref string[] clients)
{
//ask how many clients
int c = Convert.ToInt32(Console.ReadLine());
clients = new string[c];
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句