Is it possible to make array size size depended on the atribute value(int)?


class trip { private person[] arrayofpeople; public person[] arrayofpeople

get { return arrayofpeople; }
            set { arrayofpeople = value; }

}

class ship        {                   private int numberofrooms;                     public int numberofrooms          {              { return numberofrooms; }              set { numberofrooms = value; }          }            }  
question how can make when make new object type trip, arrayofpeople size of numberofrooms?

hi damjan,

maybe it's typo, public property in trip class should called arrayofpeople, because private variable called arrayofpeople (you did correctly in ship class). you'll need when setting arrayofpeople trip:

ship myship = new ship(); myship.numberofrooms = 6;  trip mytrip = new trip(); mytrip.arrayofpeople = new person[myship.numberofrooms]; 


~~bonnie dewitt [c# mvp]

http://geek-goddess-bonnie.blogspot.com



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'