Initialising an array ...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vodkasoda
    New Member
    • Sep 2011
    • 10

    Initialising an array ...

    The following command works just fine ...

    Code:
    string[] KA_Team = new string[] { "","","","","" };
    ... but is impractical if my array is going to be of a substantial size.

    How can I do this simply & effectively, allowing for an array of a probable maximum of 48 ?
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You can use new string[48] and then use a loop to initialize it.

    Comment

    • vodkasoda
      New Member
      • Sep 2011
      • 10

      #3
      Aha, quite obvious really !!! Thanks.

      Comment

      • arie
        New Member
        • Sep 2011
        • 64

        #4
        ...or you can make it any length you want.
        Code:
        int arrayLenght = 48; //or whatever
        string [] myArray = new string[arrayLength];
        This way it'll always be only as big as you want it.

        Comment

        Working...