0

I was trying to do something like:

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];
}

But when I go out of the CreateClients procedure the 'clients' array was not modified, am I missing something? I thought arrays were passed always as reference

Thanks

1 Answer 1

1

You need to pass the clients array by reference.

createClients(ref clients);

static void CreateClients(ref string[] clients)
{
  //ask how many clients
  int c = Convert.ToInt32(Console.ReadLine());
  clients = new string[c];
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.