C # learning notes (2) operator multiplication operator judgment statement loop statement comparison operator logical operator Array

Source: Internet
Author: User

Section 7
% Remainder
^ Multiplication
Section 8 simplified auto-incrementing Operators
X ++ x
Empty ~

Section 9 Multiplication

^ This symbol is not \

Section 10 judgment statements

If else statement

If (){}
Else if (){}
Else {}

Int caseSwitch = 6;
Swich (caseSwitch ){
Case1:

Break;
}

Section 1 Cyclic statements
1. while (condition) {statement ;}

2. for Loop

3. do {statement} while (condition) // execute at least once

12th comparison Operators

Comparison operators have results.

13th logical operators

The operation objects of logical operators are only true and false.
The calculation result is only true or false.

Logic operator priority! & | Parentheses can change the priority.

IsNumber is used to determine whether a string is a number.
IsNumber ("12jdj") = false
IsNumber ("26") = true

14th lecture Array

What is an array? For example:
Int [] numbers; // declare an array of the int type
Numbers = new int []; // create and declare the size
Numbers = {1, 2, 4}; // value assignment
Int num = numbers [0];

2. string [] theStrings; // declare an array of the string type
TheStrings = new string []; // create
TheStrings = new string [20]; // change the size

Array declaration Initialization
Irregular
String [] names = {"sdf", "sdf", "fdfd "};
String [] names = new string [] {"sdf", "sdf", "fdfd "};

Array Index
String [] theStrings; // declare a string Array
TheStrings = new string [10]; // create and declare the size

TheStrings [0] = "Peng ge"; // assign a value to the first element
Size of the referenced array: theString. Length

Array Traversal

String [] list = {"sdf", "sdf", "fdfd "};

Foreach (string str in list)
{
Console. WriteLine (str );
}

Foreach is safe and efficient

Multi-dimensional array (two-dimensional array)

Int [,] arr = {1, 2}, {1, 3}, {1, 4 },}

Staggered Array
Int [] [] numbers = new int [2] [];
Numbers = {new int [] {3, 4}, new int [] {6, 4 }}
An array is an array.

Code:

/*
Int x = 5; // section 7 Addition
X = x + 1;
This. textBox1.Text = x. ToString ();
//*/
/*
Int x = 9; // returns the remainder.
Int y = x % 3;
This. textBox1.Text = y. ToString ();
//*/

/*
// Difference in Section 8
Int x = 5;
Int B = ++ x;
This. textBox1.Text = B. ToString ();
//*/

/*
Int x = 5;
Int B = x ++;
This. textBox1.Text = B. ToString ();
//*/

/*
Int x = 4 ^ 3; // In the ninth section, an error occurs. 4's Power 3 is 7 2's Power 3 is 1. Why?
This. textBox1.Text = x. ToString ();
//*/
/*
Int x = 5/2;
This. textBox1.Text = x. ToString ();
//*/
/*
Int x = 5 \ 2; nonexistent
This. textBox1.Text = x. ToString ();
//*/

/*
Int x =-1; // x can receive a data in the text box;
Int y = 0; // y records the operation result;
If (x> = 2 ){
Y = x-1;
}
Else {
Y = 2 * x + 3;
}
This. textBox1.Text = y. ToString ();
//*/

/*
Int x = 3; // x can receive a data in the text box. Lecture 10
Int y = 0; // y records the operation result;
If (x> = 2 ){
Y = x-1;
}
If (x <2 ){
Y = 2 * x + 3;
}
This. textBox1.Text = y. ToString ();
//*/

/*
Int I = 0; // 11th
While (I <5 ){
This. textBox1.Text = this. textBox1.Text + "\ r \ n" + I. ToString ();
I ++;
}
//*/
/*
For (int I = 0; I <= 3; I ++ ){
This. textBox1.Text = this. textBox1.Text + "\ r \ n" + I. ToString ();
}
//*/
/*
Bool theBoolean = 5> 3; // lecture 12th
This. textBox1.Text = theBoolean. ToString ();
// ToString () is to convert true to ""
//*/

/*
Int x = 20; // 13th
If (x>-1 & x <2 ){
This. textBox1.Text = "variable x in range-1 and 2 ";
}
Else {
This. textBox1.Text = "variable x is no longer in the range ";
}
//*/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.