Search code examples
c#arraysstaticdefinitioncharacteristics

definition of static arrays


I've been looking for a decent definition of static arrays. I've tried using msdn and c# sources but cannot seem to find a definition. It gives examples, but no definitions...

Does anyone know any links or definitions and characteristics of a static array please?


Solution

  • When you talk about a 'static array' you are really talking about two separate things.

    One would be the static keyword. When applied to variables this means that the variable lives at the class level, and each object of that type will not get its own instance.

    An array is simply a data structure for holding multiple values of some type.

    So, a static array is simply an array at the class level that can hold multiple of some data type.

    For example:

    In your TravelRoute class, you may have a set number of possible destinations in a route. These could be defined like so:

    class TravelRoute {
        public static Destination[] possibleDestinations = 
               new Destination[]{
                     new Destination("New York"),
                     new Destination("Minneapolis"),
                     new Destination("NParis")
               };
    }
    

    This will define the possible destinations on a TravelRoute. You can then access the array like so:

    Destination one = TravelRoute.possibleDestinations[0];