C # basic programming knowledge

Source: Internet
Author: User

I. Static and Dynamic

HTML is static and has no database

Asp.net is dynamic and displays the ever-changing data in the database in the browser.

Ii. Development History of. net

A running system with DOS as the core 96 years ago

 

Years of Framework Version (. NET Frame Work) development tool Version (Visual Studio)

2002 1.0 vs2002

2003 1.1 vs2003

2006 2.0 vs2005

2007 3.0 vs2005

2008 3.5 vs2008

2010 4.0 vs2010

2012 4.5 vs2012

. Net Framework is a common name for a programming environment. The standard name is the common language infrastructure (CLI). The CLI is developed by Microsoft, ISO and ECMA certification standards of international standardization institutions.

. The Net Framework Program compiles the source code into the common intermediate language code, which is previously called Microsoft intermediate language (msil) code, it can only run in Common Language (CLR ).

C # Programming

(1) Project Structure

. Cs -- source file, program code

. Config -- configuration file

. Csproj -- project file (used to manage file items)

. Sln -- solution file (used to manage projects)

 

Main Function

Static void main (string [] ARGs)

{

}

In Main, m must be in uppercase.

The end of a sentence in the computer is expressed.

Four elements of a function: name, input, processing, and output

Input statement:

// Console. Readline ();

Output statement:

// Console. writeline ("Enter the content to display ");

// Console. Write ("Enter the content to display ");

The read and read keys are generally not used in the statement, and the content is assigned to S.

Line is added after write to indicate line feed.

When you need to execute the program, click Start or Ctrl + F5

Example:

// String S = console. Readline ();

// Console. Write (S + "Enter the content to display ");

 

/* String S = console. Readline ();

Console. writeline (S + "Enter the content to display ");*/

Note: s cannot be enclosed by quotation marks.

(2) Data Types

 

 

C # Language

. Net Type (general language)

Size

(Bytes)

Value

Interval

Basic

Data

Type

 

Integer

Byle

Byte

1

0 ~ 255

Short

Int16

2

 

Int

Int32

4

 

Long

Int64

8

 

Floating Point Type

Float

Single

4

 

Double

Double

8

 

Decimal

Decimal

16

 

Character Type

Char

Char

2

Any character

Boolean

Bool

Boolean

1

True or false

Reference class

String type

String

String

 

Character Sequence

Datetime type

Datetime

 

 

 

(3) variables:

1. Naming rules

1). the variable name can only consist of letters, Chinese characters, numbers, and underscores (_).

2). The first character can only contain letters, Chinese characters, and underscores (_).

3). It cannot be the same as the system keyword

2. Definition of Variables

Data type variable name [= value];

For example, int A = 10;

3. Usage of variables: Value assignment, Value

Example: A = 90;

A = a + 100;

4. Declare a variable, give the type first, and then add a semicolon after the name.

5. Separate multiple variables of the same type with commas (,) in a row.

Example: int A, B; (declare the variable type, separated by commas)

String PIE = "3.14"; (use double quotation marks)

Char c = 'M'; (use single quotes)

6. In the same statement, the same variable cannot be identified as the same type twice.

7. Shortcut Keys:

Shift + delete a row

Alt + → error source help correction

Add a line before a line // comment a line

Start/* end */comment out a Section

Press Ctrl + K + C to comment out the selected area.

CTRL + K + u uncomment

(4) Constants

1. Classification: symbolic constants, literal Constants

2. Definition of symbolic constants: Add const before variable definition

3. Use of symbolic constants: values cannot be assigned. Values can only be set.

Example:

Cons T int A = 4;

4. The extension l can be added to the direct number of long,

Float and double are writable as Integers of zero, that is, 0.5 →. 5.

The exponent part can be expressed by E or E.

Float and double values can be directly added with the suffix F, F, D, or D.

Example:

Long A = 90010000l;

2e1f 8.f. 4f 0f 3.25f 9.02e + 12f

2e1 8.. 4 0.0d 3.25 9e-9d 7e123d

5. escape characters

\ B escape key character \

\ N newline \ t Tab key character

\ R press enter \ backslash

\ 'Single quotation marks \ "Double quotation marks

(5) Operators

Category

Symbol

Explanation

Priority

 

Arithmetic

++ --

Add, subtract, and subtract

From high to low, that is, the execution sequence goes from top to bottom

*/%

Multiplication and division

+-

Subtraction

Link

><>= <=

Greater than or equal to less than or equal

=! =

Equal to not equal

 

Logic

&&

And (and)

//

Or

!

Non (Note: Priority is at the top of this table)

Condition

? :

The only ternary operator, if

Assignment

= + =-= * =/= % =

 

         

Note: parentheses have the highest priority to make the expression clearer.

// Int A = 10;

// A ++;

// Console. writeline ("A =" + );

A = 11 A ++ is used to assign a + 1 to A. At this time, a ++ and ++ A are the same.

// Int A = 10 A ++;

// Console. writeline ("A =" + );

// Error statement

 

// Int A = 10, B;

// B = A ++;

// Console. writeline ("A =" + );

// Console. writeline ("B =" + B );

A = 11 B = 10

// Int A = 10, B;

// B = ++;

// Console. writeline ("A =" + );

// Console. writeline ("B =" + B );

A = 11 B = 11

// Int A = 10, B = A ++;

// Console. writeline ("A =" + );

// Console. writeline ("B =" + B );

A = 11 B = 10

The statement has a value variable. Add the first operation before the statement.

Add and run

// Int A = 10, B = 3;

// Console. writeline (A/B );

3

// Int A = 10, B = 3;

// Console. writeline (1.0 * A/B );

3.333 ......

// Int A = 10, B = 3;

// Console. writeline (a/B * 1.0 );

3

// Int A = 10, B = 3;

// Console. writeline (A/(B * 1.0 ));

3.333 ......

An integer expression generates an integer. The floating point expression returns a floating point number.

// Console. Write ("Enter the number less than 100 ");

// String S = console. Readline ();

// Int num = convert. toint32 (s );

// Console. writeline (Num % 7 = 0); multiple of 7

// Console. writeline (Num/10 = 7); 10 is 7

// Console. writeline (Num % 10 = 7); the single digit is 7

 

(6) type conversion

A combination of any valid operators and operands is called an expression.

The return value of a Boolean expression is true or false.

The computer can only perform operations on the same type

Classification: constant transformation (same type) width conversion (implicit automatic) narrow conversion (forced display)

Example:

Float;

Double B = 3.14;

A = B;

This statement reports an error. The float function can be reflected in the double type. Otherwise, an error occurs.

For example, float a = 8.32; an error is reported (the system sets 8.32 to double by default)

Float a = 8.32f; normal (tell the system to read with single precision)

Double A = 8.32; normal

Doule A = 8.32f; normal

The preceding statement can be modified in three ways.

  1. A = (float) B; applies to the value assignment to be forcibly read between the same type
  2. A = convert. tosingle (B); applicable to value types
  3. A = float. parse (B); parses the string into a value type.

Example: Correct

Float;

String B = "3.14 ";

A = B;

This question can only be solved in two or three ways (not of the same type)

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.