Declaring / Initializing
int[] robsArray;
robsArray = new int[10];
//or
const int MYSIZE = 10
int[] robsScores = new int[MYSIZE];
//or
int[] RobsNumbers = new int[5] {1, 2, 3, 4, 5};
//aka
int[] RobsNumbers = {1, 2, 3, 4, 5};
//types
string[] robsFriends = {"Robert", "Frank", "Peter"};
double[] robsDooble = {2.99, 4.55, 5.76566};
add suff to array
!doesnt work
string[] robsCool = new string[3];
robsCool[0] = "cool";
robsCool[1] = "awesome";
robsCool[2] = "amazing";
loop foreach
int[] robsNumbers = {4, 5, 6, 1, 2, 3, -2, -1, 0};
foreach (int robsTemp in robsNumbers)
{
//MessageBox.Show("Rob number is " + robsTemp.ToString());
listBox1.Items.Add(robsTemp);
}
pass array to function
private void displayArrayStr(string[] passedArray)
{
listBox1.Items.Clear();
foreach (string robsTemp in passedArray)
{
listBox1.Items.Add(robsTemp);
}
}
//button event
{
string[] robsCars = { "Ford", "Volkswagen", "Bronco" };
displayArrayStr(robsCars);
}