while Loop (Initialize, Compare, Alter) : Exam 2 Study Guide Chapter 5-Arrays
while Loop (Initialize, Compare, Alter) : Exam 2 Study Guide Chapter 5-Arrays
Show(Hello); Count = count +1; // count++; } MessageBox.Show(Goodbye); //for loop (initialize, compare, alter) for( count = 0; count <4; count++) { MessageBox.Show(Hello); } Chapter 6- Arrays // declare a single-dimensional array int[] array1 = new int[5]; // declare and set array element values int[] array2 = new int[] { 1, 3, 5, 7, 9 }; // Alternative syntax int[] array3 = { 1, 2, 3, 4, 5, 6 }; //using loop to initialize an array int = x; for(x=0; x < money.Length; ++x;) { money[x] = 100; } // searching an array
int[] validId = {125,137,212,244}; double idNumber = Double.Parse(this.textBox2.Text); bool isValid = false; int x = 0; while (x <validId.Length && idNumber != validId[x]) { x++; } if (x != validId.Length) { isValid = true; } if (isValid) { MessageBox.Show("ID is valid");} else { MessageBox.Show("ID is NOT valid");}
Chapter 7- Methods //main method that will execute in the application //void does not return a value //string returns value //public= anyone can access; static = no object has to exist; void= no value returned public static void Main() {/* Method statements here */ }
//Pass an array to method private void Main() { double[] fees = { 2.99, 4.99, 6.99 }; IncreaseAFee(fees); MessageBox.Show("Amount is " + fees[1]); } private void IncreaseAFee(double[] amount) { const double Increase = 1.50; MessageBox.Show("Amount is " + amount[1]); amount[1] = amount[1] + Increase; MessageBox.Show("Amount is " + amount[1]); }
//call a function private void button1_Click(object sender, EventArgs e) { textBox1.Text = CurrentTime(6); } private String CurrentTime(Int16 n) { if (n > 5) { return DateTime.Now.ToString(); } else { return "Test"; } } Chapter 8//Ref-has no starting value //Out-variable has no starting value