0% found this document useful (0 votes)
25 views2 pages

while Loop (Initialize, Compare, Alter) : Exam 2 Study Guide Chapter 5-Arrays

This document provides a study guide covering chapters 5-8 on arrays, loops, methods, and parameters in C#. Key points include: 1) How to use while and for loops to iterate through arrays and display output. 2) Different ways to declare and initialize single-dimensional arrays, including using a for loop. 3) How to search an array to check if a value is valid and display corresponding output. 4) The basics of defining and calling methods, including different parameter types like void, string, and passing arrays to methods.

Uploaded by

Ken Le
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views2 pages

while Loop (Initialize, Compare, Alter) : Exam 2 Study Guide Chapter 5-Arrays

This document provides a study guide covering chapters 5-8 on arrays, loops, methods, and parameters in C#. Key points include: 1) How to use while and for loops to iterate through arrays and display output. 2) Different ways to declare and initialize single-dimensional arrays, including using a for loop. 3) How to search an array to check if a value is valid and display corresponding output. 4) The basics of defining and calling methods, including different parameter types like void, string, and passing arrays to methods.

Uploaded by

Ken Le
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Exam 2 Study Guide Chapter 5- Arrays //while loop (initialize, compare, alter) count = 0; while (count <4 ) { MessageBox.

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy