Initializing arrays

Here’s a handy way of creating an array and pass it as a parameter for a function call:

MyFunc(new Kommentar[] {kom1, kom2} );

No need for clumsy temporary variables etc. Neat, isn’t it?

Here’s another variation:

VeckoFacit[] facitarr;
facitarr = new VeckoFacit[]
{
    new VeckoFacit(...),
    new VeckoFacit(...),
    new VeckoFacit(...)
};

Initializing a multidimensional array:

int[,] intArray = new int[3, 2] { {1, 2}, {3, 4}, {5, 6} };
int[,] intArray = new int[,] { {1, 2}, {3, 4}, {5, 6} };

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.