Tutorials Navigation

Tutorials :: New :: Popular :: Top Rated

Tutorials: 18,326 Categories: 12

Total Tutorial Views: 41,458,692

[C#] Arrays

Tutorial Name: [C#] Arrays  

Category: PC Tutorials

Submitted By: Skittle

Date Added:

Comments: 0

Views: 681

Related Forum: PC Building Forum

Share:

This tutorial is in C#, if you would like me to explain the code in Visual Basic then PM me
An array is a collection of variables, just think of it as a table, You declare and array and reference the different elements (each element holding another variable with an index, starting at 0. The first element is 0, the second element is 1 etc.
Here is how you declare arrays:

int[] myIntArray;

Declaring an array this way will not have a set amount of elements. You can declare it this way to set the number of elements:

int[] myIntArray = new int[3];

The rule I explained at the beginning with the index starting at 0 doesn't apply to array declaration, so this array has 3 elements: 0, 1 and 2. Let me set some values to the array:

myIntArray[0] = 5;
myIntArray[1] = 10;
myIntArray[2] = 15;

Here is a table to try and help you understand the array:

[ Register or Signin to view external links. ]

Now that we have some values in our array, lets print them out to show what we have got:

for(int i = 0; i < myIntArray.Length; i++) //goes through each element in myIntArray[]
{
    Console.WriteLine("Element: " + i + " = " + myIntArray[i]); //prints out result
}
Console.ReadLine(); //this stops the program from ending instantly

The code displays this when ran:
[ Register or Signin to view external links. ]


This is only the basics or arrays, if you want to know more about them then leave a comment letting me know!
If you need any help with this tutorial then feel free to PM me

Ratings

Current rating: 6.50 by 2 users
Please take one second and rate this tutorial...

Not a Chance
1
2
3
4
5
6
7
8
9
10
Absolutely

Comments

"[C#] Arrays" :: Login/Create an Account :: 0 comments

If you would like to post a comment please signin to your account or register for an account.