Using String Array as Object Argument

So, I have a class that has a string array argument. What I want to do is store multiple lines for this array, which 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!

+3


source to share


2 answers


Remove the parentheses from the selector number when placing it in the Event constructor.



For reference.

+3


source


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

.

Event show = new Event(seatnumber);

      

This is the same as what you previously called in your code:



this.seats = seats;

      

seats

is also an array, although you didn't add []

when you called it, so no errors.

+3


source







All Articles