Initializing Array Elements

You can initialize the contents of an array at the time you create it by providing a list of values delimited by curly braces ({}). C# provides a longer and a shorter syntax:

int[] myIntArray = new int[5] { 2, 4, 6, 8, 10 };
int[] myIntArray = { 2, 4, 6, 8, 10 };

In the shorter syntax, C# automatically creates an array of the proper size for the number of elements in the braces. There is no practical difference between these two statements, and most programmers will use the shorter syntax.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset