C # Summary 2-2

Source: Internet
Author: User

The fourth chapter procedure flow

4.01 Flowchart
1 Flowchart: Use standardized graphic schemes to analyze the practice steps of a feature.
2. Draw the flowchart according to the function and write the code according to the flowchart. Separate functional analysis and code writing to focus on complex issues.
3.
4.02if judgment
1. where (condition 1) (condition 2) is a bool type, (code 1) (Code 2) (code n) can be repeated any number of times.
The function of 2.if judgment is on the Process Control statement, besides this, switch table selection, loop statement.
3. The three mesh operator is a simplified version of If judgment.
4. Determine if A is zero, positive odd, positive even, negative odd or even
4.03 Scope of variables
1. The scope of a variable can be simply understood as the curly brace in which a variable is defined. Within parentheses, the variable is valid and outside the curly brace is invalid.
Boxing
Date
When defining a variable in a location, the variable name must not be the same as the variable name where the scope overrides the location
4.04 Profit Calculator
4.05switch selection
1. Where break must be written, (value 1), (value 2) must be a specific value cannot be a variable or an expression, and can be compared with (a variable or an expression).
2.switch can be converted to if judgment, and if judgment is not necessarily convertible to Switch,switch only supports the following types: String,char, enum, Integer (cannot use double type), BOOL, etc.
3.
4.06while Cycle
1. The loop condition can be a value, a variable, an expression, and a return type must be of type bool. The loop body can be any function, any number of code.
2. Loop: Do one thing over and over again. The Loop statement has While,do While,for,foreach.
4.07 Dowhile Cycle
Reading
2. Note the scope of the variable.
4.08for Cycle
1. Expression 2 can also be arbitrary code, executed after the loop body executes.
4.09 Printing 99 Multiplication table
4.10break and Continue
1.break
1.switch to end switch selection now
2. Loop ends the loop immediately (ends the current loop).

2.continue is used only for loops, which means that the current loop is ended immediately and into the next loop.

4.11 Finding problems
1. Find the required data in a set of data according to your needs.
2. Simple search: In the sample, looking for the target data in turn, will use the loop.
3. The cycle must start from the first data of the sample, after the end of the last data of the sample, the loop body must include a judgment to determine whether the current data, the target data.
Fifth Chapter

5.01 arrays
1. String type, numeric type, bool (Boolean) type, only one data can be stored. Arrays can hold any number of data of the same type.
2. The index or subscript of an array is a number of type int, incrementing from the number 0.
3. Declaration and assignment of arrays
A. Declaration: Data type [] variable name;
B. Variable name =new data type [length]; (where [Length]int type represents the length of the array.) You can also make merge declarations, and the variable names and data types must be identical.
4. Reading and modifying array items
A. READ: variable name [index]; Removes the value of an array item from the specified array by number, where [index] is the number of the item and cannot exceed the maximum subscript.
B. Modify: variable name [index]= value;
5. After an array item is created, it does not have an array entry value, which is the default value for the type of the item. For example, the default value for the numeric type is 0;char type (null character), and the default value for bool type is flase;string type, which is null (for null).
6. Array initializer: variable name =new data type [length]{element 1, Element 2, .... Element n};
5.02 fixed staying power of arrays
1. Once an array is created, its length is fixed.
2. such as int[] numbers=new int[3]l;
numbers[0]=3;
Numbers=new int[2]; rebuilds an array of length 2.
Console.WriteLine (number[0]); output is 0.
3. Arrays are suitable for scenarios where the number of data is fixed, such as saving prime numbers within 100.
5.03 traversal of an array
1. The traversal of an array is the beginning of the first item in the array, followed by the completion of all items in the array.
2. The loop variable starts at 0 and then takes the largest subscript of the array (the length of the array-1). In the loop body, you can use the loop variable as the subscript to remove the value of each item in the array.
3.
5.04 switching sort
1. Exchange sort: As you can see, no matter how long the nums is, you can use this code format:
for (int i = 0; i < Nums. Length-1; i++)
{
In the I-(nums. LENGTH-1) within the range, the smallest number in the range is referred to I
}
So, as long as the comment section is resolved, the whole sort is done!
So how to put I-(nums. LENGTH-1) The smallest number in the range refers to position I?
In this issue, the interchange sort is done in the following ways:
1. Compare position I and position i+1, if larger than i+1, then swap
2. Compare position I and position i+2, if larger than i+2, then swap
3 .....
4. Place the position I and position nums. Length-1 to compare if compared to nums. Length-1 large, then Exchange
for (int i = 0; i < Nums. Length-1; i++)
{
In the I-(nums. LENGTH-1) within the range, the smallest number in the range is referred to I
for (int j = i + 1; j < Nums. Length; J + +)
{
if (Nums[i] > Nums[j])
{
Exchange
int temp = Nums[i];
Nums[i] = Nums[j];
NUMS[J] = temp;
}
}
}

2. Bubble sort can be seen, regardless of the length of nums, you can use this code format:
for (int i = Nums. Length-1; i > 0; i--)
{
Within the range of 0-i, the largest number in the range is sunk to I
}
So, as long as the comment section is resolved, the whole sort is done!
So how do you sink the largest number in the 0-i range to position I?
On this issue, the bubbling sort is done in the following ways:
1. Compare position 0 and position 1, if the former is larger than the latter, then swap
2. Compare position 1 and position 2, if the former is larger than the latter, then swap
3 .....
4. Compare position i-1 and position I, if the former is larger than the latter, then swap
for (int i = Nums. Length-1; i > 0; i--)
{
Within the range of 0-i, the largest number in the range is sunk to I
for (int j = 0; J < i; J + +)
{
if (Nums[j] > Nums[j+1])
{
Exchange
int temp = Nums[j];
NUMS[J] = nums[j+1];
NUMS[J+1] = temp;
}
}
}

3. The general idea of selecting sort selection sorting and the general idea of exchange sorting are similar in that the smallest number in a range refers to the first bit in the range, and its code structure is identical to the interchange sort:
for (int i = 0; i < Nums. Length-1; i++)
{
//In I-(nums. LENGTH-1) within the range, the smallest number in the range referred to I
}
the knowledge in the Implementation comment section produces a difference, the idea of choosing sort is:
1. First find I-(nums. LENGTH-1) The lowest number within the range is the subscript, assuming that the found subscript is saved to the variable index
2. Then exchange the values of nums[i] and Nums[index]
for (int i = 0; i < Nums. Length-1; i++)
{
//In I-(nums. Length-1), the smallest number in the range is referred to I
//1. First find I-(nums. LENGTH-1) The lowest number in the range is the subscript
int index = i;/////First assume that the subscript of the minimum number is I
for (int j = i + 1; j < Nums. Length; J + +)
{
if (Nums[j] < Nums[index])
{
//found smaller number
index = j;//record subscript
}
}
//2. Then nums[i] and nums[ Value of index] Interchange
int temp = nums[i];
Nums[i] = Nums[index];
Nums[index] = temp;
}

5.05 Array Analyzer
5.06 Integrated
1. Arrays and collections are used to store multiple data of the same type. Array: 1. Fixed length 2. Take up less memory and traverse fast. Set: 1. The amount of data saved can change continuously during the execution of the program. 2. Memory-intensive, slow traversal.
2. The function of all the functions of the digital can be achieved, the collection can be implemented, conversely, the collection can achieve some functions, arrays are difficult to achieve.
The 3.c# language supports collection types such as: List (the most common collection type), Queve,stack,hashset.
4.
5.07foreach Cycle
1.foreach, loops can only be used to iterate over arrays and collections.

5.01 arrays
1. String type, numeric type, bool (Boolean) type, only one data can be stored. Arrays can hold any number of data of the same type.
2. The index or subscript of an array is a number of type int, incrementing from the number 0.
3. Declaration and assignment of arrays
A. Declaration: Data type [] variable name;
B. Variable name =new data type [length]; (where [Length]int type represents the length of the array.) You can also make merge declarations, and the variable names and data types must be identical.
4. Reading and modifying array items
A. READ: variable name [index]; Removes the value of an array item from the specified array by number, where [index] is the number of the item and cannot exceed the maximum subscript.
B. Modify: variable name [index]= value;
5. After an array item is created, it does not have an array entry value, which is the default value for the type of the item. For example, the default value for the numeric type is 0;char type (null character), and the default value for bool type is flase;string type, which is null (for null).
6. Array initializer: variable name =new data type [length]{element 1, Element 2, .... Element n};
5.02 fixed staying power of arrays
1. Once an array is created, its length is fixed.
2. such as int[] numbers=new int[3]l;
numbers[0]=3;
Numbers=new int[2]; rebuilds an array of length 2.
Console.WriteLine (number[0]); output is 0.
3. Arrays are suitable for scenarios where the number of data is fixed, such as saving prime numbers within 100.
5.03 traversal of an array
1. The traversal of an array is the beginning of the first item in the array, followed by the completion of all items in the array.
2. The loop variable starts at 0 and then takes the largest subscript of the array (the length of the array-1). In the loop body, you can use the loop variable as the subscript to remove the value of each item in the array.
3.
5.04 switching sort
1. Exchange sort: As you can see, no matter how long the nums is, you can use this code format:
for (int i = 0; i < Nums. Length-1; i++)
{
In the I-(nums. LENGTH-1) within the range, the smallest number in the range is referred to I
}
So, as long as the comment section is resolved, the whole sort is done!
So how to put I-(nums. LENGTH-1) The smallest number in the range refers to position I?
In this issue, the interchange sort is done in the following ways:
1. Compare position I and position i+1, if larger than i+1, then swap
2. Compare position I and position i+2, if larger than i+2, then swap
3 .....
4. Place the position I and position nums. Length-1 to compare if compared to nums. Length-1 large, then Exchange
for (int i = 0; i < Nums. Length-1; i++)
{
In the I-(nums. LENGTH-1) within the range, the smallest number in the range is referred to I
for (int j = i + 1; j < Nums. Length; J + +)
{
if (Nums[i] > Nums[j])
{
Exchange
int temp = Nums[i];
Nums[i] = Nums[j];
NUMS[J] = temp;
}
}
}

2. Bubble sort can be seen, regardless of the length of nums, you can use this code format:
for (int i = Nums. Length-1; i > 0; i--)
{
Within the range of 0-i, the largest number in the range is sunk to I
}
So, as long as the comment section is resolved, the whole sort is done!
So how do you sink the largest number in the 0-i range to position I?
On this issue, the bubbling sort is done in the following ways:
1. Compare position 0 and position 1, if the former is larger than the latter, then swap
2. Compare position 1 and position 2, if the former is larger than the latter, then swap
3 .....
4. Compare position i-1 and position I, if the former is larger than the latter, then swap
for (int i = Nums. Length-1; i > 0; i--)
{
Within the range of 0-i, the largest number in the range is sunk to I
for (int j = 0; J < i; J + +)
{
if (Nums[j] > Nums[j+1])
{
Exchange
int temp = Nums[j];
NUMS[J] = nums[j+1];
NUMS[J+1] = temp;
}
}
}

3. The general idea of selecting sort selection sorting and the general idea of exchange sorting are similar in that the smallest number in a range refers to the first bit in the range, and its code structure is identical to the interchange sort:
for (int i = 0; i < Nums. Length-1; i++)
{
//In I-(nums. LENGTH-1) within the range, the smallest number in the range referred to I
}
the knowledge in the Implementation comment section produces a difference, the idea of choosing sort is:
1. First find I-(nums. LENGTH-1) The lowest number within the range is the subscript, assuming that the found subscript is saved to the variable index
2. Then exchange the values of nums[i] and Nums[index]
for (int i = 0; i < Nums. Length-1; i++)
{
//In I-(nums. Length-1), the smallest number in the range is referred to I
//1. First find I-(nums. LENGTH-1) The lowest number in the range is the subscript
int index = i;/////First assume that the subscript of the minimum number is I
for (int j = i + 1; j < Nums. Length; J + +)
{
if (Nums[j] < Nums[index])
{
//found smaller number
index = j;//record subscript
}
}
//2. Then nums[i] and nums[ Value of index] Interchange
int temp = nums[i];
Nums[i] = Nums[index];
Nums[index] = temp;
}

5.05 Array Analyzer
5.06 Integrated
1. Arrays and collections are used to store multiple data of the same type. Array: 1. Fixed length 2. Take up less memory and traverse fast. Set: 1. The amount of data saved can change continuously during the execution of the program. 2. Memory-intensive, slow traversal.
2. The function of all the functions of the digital can be achieved, the collection can be implemented, conversely, the collection can achieve some functions, arrays are difficult to achieve.
The 3.c# language supports collection types such as: List (the most common collection type), Queve,stack,hashset.
4.
5.07foreach Cycle
1.foreach, loops can only be used to iterate over arrays and collections.
7th Chapter function

7.01 cognitive functions
1. Duplicate code has the following disadvantages: 1. Low efficiency 2. High cost 3. Easy error 4. Difficult to repair. 5. Difficult to read.
2. function has independent function, and can be reused by name code
3. The function uses a call called a function, which must first be declared before calling
5. Syntax for function declaration: static void Function name () {//Function body (arbitrary function, any number of code)}
6. The function body of the function is executed when the program runs to the statement that invokes the function. Syntax for function call: function name ();.
7.02 scope and identifier of the function
1. A variable that is valid only in the curly braces it defines.
2. Variable in different scopes, with independent memory space
3. When the scope ends, the amount of data is removed from memory.
4. Different functions, the variables are independent of each other, each time the call to the function is run independently.
5. The name of the function names of the first letter to uppercase, hump name method, do hope the text know. such as: Getprime.
7.03 declaring a function with parameters
1. Parameters, to complete one thing need to know the additional conditions. Parameter list writing syntax:
Data type parameter name, data type parameter name, .....
2. In the function body, you can use a parameter as an already declared variable.
3. The scope of the parameter is valid only in the function body.
4. When declaring a function, the parameter must include the data type and parameter name.
7.04 calling a function with parameters
1. function declaration Syntax:
public static void function name (formal parameter list) {//comment contents}
Each formal parameter in the parameter list is written in the syntax: data type parameter name, data type parameter name, .....
2. Function call Syntax: function name (argument list)
The writing syntax for each argument in the argument list: a value or variable or expression where the type cannot be labeled.
3. The number and type of arguments must correspond exactly to the formal parameters (not related to the variable name).
4. When a function with parameters is called, the data of the argument is passed (assigned) to the parameter.
Sub-topic 5
Sub-topic 6
7.05 declaring a function with a return value
1. Function: do one thing; parameters: do an extra condition that you need; return value: The result of the thing being done.
2. Syntax for function declaration: Static return type function name (formal parameter list) {//function body}
The resulting type (void is a special return type that indicates no return type) after the function is completed
3.return keywords
Used to return a result in the body of a function, using syntax: return value or variable or expression;
When the code runs to the return statement: 1. End Function immediately 2. Returns the result of the value, variable, or expression following the return keyword.

7.06 calling a function with a return value
1. Function call Syntax: function name (argument list);
A function call is an expression, and the return type is consistent with the return type of the function declaration, which refers to a separate function.
2. The main function needs to save the result of the calling function.

7.07 function signatures
1. A function signature is a function name, a list of parameters, and a general designation of the return type.
2. Function names can represent function functions (add means add, IsPrime is not prime).
3. Parameter list: The function needs additional information to complete its function.
4. Return type: After the function completes the function, the resulting type of the result, if no need to produce the result return type is void. The function signature is the object that is implemented in the function body.
7.08 Documentation Comments
1. The comment of the code has a single line comment, a multiline comment, and a document comment.
2. Single-line comments and multiline comments are usually written in the body of the function to describe the code in the body of the function.
Document comments are usually written to code outside the body of the function. 3 slashes in VS represent//.
7.09 Overloading of functions
1. Function overloading (overload) means that multiple functions can use the same function name, only their parameter list is different (the number of arguments is different or the parameter type is different).
2. The role of overloading: function overloading, can be similar to the meaning of the function, named the same name, which reduces the difficulty of the call.
4. Calling an overloaded function is exactly the same as calling a normal function. Depending on the type of argument passed, the computer matches the most appropriate overload.
7.10 Mutual invocation of functions
1. In any function body, you can call the function
2. In the writing function body, can make full use of their own functions to complete the function to reduce the difficulty
7.11 Recursion
1. Recursion refers to a function that calls itself directly or indirectly.
2. Recursion must have a termination condition, otherwise infinite recursion will occur. Infinite recursion can cause memory crashes and must be avoided.
3. Fibonacci Sequence

C # Summary 2-2

Related Article

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.