.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Arrays

Posted By:Shashi Ray       Posted Date: February 23, 2009    Points: 15    Category: C#    URL: http://www.dotnetspark.com  
 

Arrays

 

In C#, all arrays are zero based. If you declare an array as

 

int[] x = new int[10];

 

such arrays have 10 elements, numbered from 0 to 9. Thus, arrays are in line with the style used in C, C++ and Java.

 

const int MAX = 10;

float[] xy = new float[MAX];

for (int i = 0; i < MAX; i++ )

{

xy[i] = i;

}

 

You should get into the habit of looping through arrays to the array bounds minus one as we did in the above example.

 

All array variables have a length property so you can find out how large the array is:

 

float[] z = new float[20];

for (int j = 0; j< z.Length ; j++)

{

z[j] = j;

}

 

Arrays in C# are dynamic and space can be reallocated at any time. To create a reference to an array and allocate it later within the class, use the syntax:

 

float z[]; //declare here

z = new float[20]; //create later

 

Shashi Ray


 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend