C#

C# IF ListBox Arrays 2D Arrays Read File Example 1 Example Midterm 1 Example Midterm 2 Example 5 Example 7 Group Project 2 Example 9 Group Project 2
O O

Weather Controls

Time Of Day
Rain
Wind Speed
Wind Direction
Clouds

C# : Arrays

2017-01-01

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);
}