DTR4iN91
DTR4iN91

Reputation: 31

Using String Array As Object Argument

So I have a class that has an argument of a string array. What I want to do is store multiple strings to this array that is part of this class. The code looks something like this:

//Class part of it. Class is called "Event"
public class Event
{
   public string[] seats = new string [75];

   public Event(string[] seats)
   {
      this.seats = seats;
   }
}

// the main code that uses "Event" Class

string[] seatnumber = new string[75];
Event show = new Event (seatnumber[]); //And that is where the error comes in. 

Any help would be greatly appreciated!

Upvotes: 3

Views: 52

Answers (2)

Ben
Ben

Reputation: 2523

When you call an array, the variable name does not need the brackets [].

Event show = new Event(seatnumber);

It the same as you called earlier in your code:

this.seats = seats;

seats is also an array, though you haven't added the [] when you called it - so no error.

Upvotes: 3

Joe Urc
Joe Urc

Reputation: 487

Remove the brackets from seatnumber when putting it in the Event constructor.

For reference.

Upvotes: 3

Related Questions