Section 10.3. Initializing Array Elements


10.3. Initializing Array Elements

You can initialize the contents of an array at the time it is instantiated by providing a list of values delimited by curly brackets ( {} ). 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 brackets. There is no practical difference between these two statements, and most programmers will use the shorter syntax.



Learning C# 2005
Learning C# 2005: Get Started with C# 2.0 and .NET Programming (2nd Edition)
ISBN: 0596102097
EAN: 2147483647
Year: 2004
Pages: 250

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net