C # 10 Total review

Source: Internet
Author: User

Data types -- variables and constants - - operators and Expressions -- statements (if,for)-- Arrays -- function -- Structural Body

First, the data type:

(i) Built-in type

Integral type (int short long byte uint ushort ulong sbyte), floating point (double float decimal), Boolean ( BOOL), character (char)

There is a ToString (" formatted string ")for integral and floating-point types:

#--any number. Some words are displayed, not on the display.

0--must have a number, if not, make up 0.

. --Decimal point

,--thousands separated.

(ii) commonly used classes

Math DateTime String

Math:

Math.ceiling (Double): the smallest integer greater than the current decimal.

Math.floor (Double): The largest integer less than the current decimal.

Math.Round (Double): Rounding

Datetime:

Year,month,day,hour,minute,second,millisecond,dayofweek,dayofyear

AddYears (n), AddMonths (), AddDays () .....

ToString (" formatted string "): Format display.

Yyyy,yy-year. mm,m--month. dd,d--days. hh,h--When. mm,m--minutes. ss,s-seconds. Ms--MS

(iii) Custom type

struct

Second, variable and constant:

(a) A variable is a container for loading data. --U - plate

Defined:

Data type variable name [= value ], variable name [= value ],....;

int A, B; int a = 5,b;

Naming rules for variables:

1. variable names can only be composed of letters, numbers, underscores

2. only letters, underscores start

3. cannot repeat with keyword.

Assignment value:

Variable name = value ; --NOTE: The variable type is consistent with the value type on the right side of the equals sign. Inconsistency requires a type conversion.

Type conversions:

1. Automatic conversion: generally automatic conversion, as long as there is no possibility of data loss, the calculation will be automatically converted. For example:Double A = 3+5.0;

2. cast: As long as there is the possibility of data loss, the computer will not be automatic conversion, need to manually forced conversion.

Convert.toxxx (); Convert.ToInt32 ();

Double A = 3.14;

int b = (int) A;

Value: Write the variable name directly.

(b) Constants: Constants are also containers for data, but constants cannot be placed on the left side of the order during operation. --Disposable discs

Category: Literal constants, symbolic constants.

Definition:const int PI = 3.14;

Note: Constants must be assigned when they are defined.

Value: Use the constant value directly.

Third, Operator:

Arithmetic, relationship, logic, other

(i) arithmetic--7

+ - * / % ++ --

Integer, in addition to integers or integers.

(ii) Relationship--6

= = = > >= < <=

(c) Logic--3

&& | | !

(iv) Other

1. composite Operator:+ = = *=/=%=

2. Assignment: =

3. conditional operator: expression 1? An expression 2: An expression 3

Iv. statements: Order, branching, looping

(i) branch--if

if ( an expression )

{

}

if ( an expression )

{

}

Else

{

}

if ( an expression )

{

}

else if ( expression )

{

}

...

Else

{

}

if ( an expression )

{

if ( an expression )

{

}

Else

{

}

}

Else

{

...

}

Example:

1. Judging leap years, common year

2. the case of the root of a unary two-time equation

3. weight and height of men and women

4. determine if the date is correct.

(b) Circulation

For ( initial conditions ; Cycle Conditions ; variable Change )

{

Loop body

}

Four elements of a loop:

Loop nesting: Prints an asterisk.

Two kinds of problems: Iterative method and exhaustive method.

Iterative method: The solution is solved by cyclic iteration according to a certain rule.

Ask for the number of the same and the factorial.

1.5 A child, asking for age .

2. placing grain on the board

3. origami with the height of Everest.

4. drop the ball problem.

5. Monkeys eat peaches

6. rabbits give birth to rabbits.

Exhaustive method: Take all the circumstances to go through, according to the conditions of screening.

The number of 7 -related numbers within the range.

1. buy something.

2. Hundred Chicken Hundred money, hundred Ma Baishi.

3. Scout

4. ask for an equation.

Five, array:

Thinking: Solve a large number of similar data storage and operation problems.

Features: continuous, same class of data.

Category: One-dimensional arrays, two-dimensional arrays, multidimensional arrays.

One-dimensional arrays:

Defined:

Data type [] array name = new data type [ length of array ] [{ initialize }];

Assignment value:

Array name [ subscript ] = value ;

Can be combined with loops.

Value:

Array name [ subscript ];

Can be combined with loops.

Example:

1. Player Rating

2. election of the monitor

3.36 selection 7

3. Green song race.

Two-dimensional arrays:

Defined:

Data type [,] array name = new array type [ number of rows , number of columns ] [{ Initialize }];

Assignment value:

Array name [ row subscript , column subscript ] = value ;

Value:

Array name [ row subscript , column subscript ];

Example:

1. student performance.

2. Push the box.

Two applications: Binary lookup, bubble sort.

Binary method to find the idea: The premise is that the array is ordered, each time to find the middle of the value of the comparison, whether the condition is thrown half.

Use the maximum subscript max, min subscript min, mid-value subscript mid, and control the range of lookups.    mid = (max+min)/2; max = mid+1; min = mid-1;

If you keep checking the min>max , it's over, and the instructions are not found.

Bubble sort idea: The adjacent two numbers are sequentially contrasted and interchanged.

Two-layer loop, outer loop number, inner loop number of times per trip.

Number of trips:n-1

Number of times:n-i

for (int i=1;i<=n-1;i++)

{

for (int j=1;j<=n-i;j++)

{

if (A[j] > A[j-1])

{

Swap.

}

}

}

Six, Function:

What is a function: the ability to complete a separate function module can be called a function.

Why use functions: Clear structure, Division of labor Development, code reuse.

Four elements: function name, formal parameter, return type, function body.

Definition syntax:

return type function name ( formal parameter list )

{

function body

}

Call:

Function name ( argument list );

The variable name of the data type = function name ( argument list );

The problem of the function's transmitting value and the address.

1. built-in type, date time is the default value. --ref

2. array, the string is transmitted by default.

The return value of the function. --return value or variable ; to keep return the type that follows is the same as the return type of the function.

Recursion. Himself to tune himself.

Grammatical thought:

return type function name ( parameter )

{

1. End the judgment of recursion.

2. recursive operation: function name ( parameter );

}

VII. structure of the body:

Why use structs? A composite type that you define yourself to better mimic the various objects in your life.

Defined

struct structure Body name

{

Public type sub-variable name ;

Public type sub-variable name ;

....

}

Use:

struct body name struct variable = new struct name ();

struct variable . Child Variables =  value ;

struct variable . Child Variables ;

struct array:

struct type [] array name = new struct type [ length ];

Array name [ subscript ]. Child Variables

How to use loops to manipulate an array of structs.

Example: Student performance statistics. PvP Games.

C # 10 Total review

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.