C#main function

Source: Internet
Author: User
Tags arithmetic operators

Main function:
static void Main (string [] args)
{

}
The program code needs to be written in the curly braces of the main function.

First, output:
Console.WriteLine ("This is my first program.") "); Wrap line
Console.WriteLine ("This is the second line of code. "); Wrap line
Console.Write ("This is the text to be output. Note: No Line break
Attention:
1. Case sensitive;
2. all symbols are in English ;
3. Don't miss out;

Second, enter:
string s = Console.ReadLine ();
This means reading a whole line of content from the console program into the container of S.
Console.WriteLine ("What you just entered is:" +s);

Accept all characters until the Enter command is received
string-Types of strings
S-Variable name
=-value Assignment

The plus sign is a concatenation when encountering string types
Console.ReadLine (); -Reads an entire line from the console program


Third, comments and [uncomment]:
1. Select the appropriate line and click the comment in the toolbar to select the line [uncomment the selected row];
2. Select the appropriate line and use the shortcut key: Ctrl+k Ctrl + C [Ctrl+k Ctrl+u]
3. Manual Comment: Add//(note an entire line) in front of the line
4. Note One of the code:/* This is the code */
5. Role of annotations: explanatory notes

Skills:
1. Write the code to use the IntelliSense function as much as possible;
2. First write the whole, then perfect the details;
3. Automatically complete the word function. alt+→

Case: Enter name, age, unit, and integrate into a fluent sentence display.
Console.Write ("Please enter Name:");
String a = Console.ReadLine ();
Console.Write ("Please enter Age:");
String B = Console.ReadLine ();
Console.Write ("Please enter the unit:");
String c = Console.ReadLine ();

Console.WriteLine ("My Name is +a+", this year "+b+" years old, in the "+c+" training. ");

My name is * *, this year * * years old, in the * * training. "Take a,b,c into the * *."
"My name is" +a+ ", this year" +b+ "years old, in the" +c+ "training. "

Iv. Types of data

Big class Small class C # language . NET language (Common language) Description Size (bytes) Value Range
Base data type (value type) Integral type SByte SByte 8-bit signed integer 1 -128~127 (negative 2 of 7 square ~ Positive 2 of 7 times minus 1)
Short Int16 16-bit signed integer 2 -32768~32767 (negative 2 of 15 square ~ Positive 2 of 15 times minus 1)
Int Int32 32-bit signed integer 3 (negative 2 of 31 square ~ Positive 2 of 31 times minus 1)
Long Int64 64-bit signed integer 4 (negative 2 of 63 square ~ Positive 2 of 63 times minus 1)
Byte Byte 8-bit unsigned integer 1 0~255 (0~2 8-time minus 1)
UShort UInt16 16-bit unsigned integer 2 (0~2 16-time minus 1)
UInt UInt32 32-bit unsigned integer 3 (0~2 32-time minus 1)
ULong UInt64 64-bit unsigned integer 4 (0~2 64-time minus 1)
Floating point Type Float Single 32-bit single-precision floating-point number 4 1.5x10−45 to 3.4x10
Double Double 64-bit double-precision floating-point number 8 5.0x10−324 to 1.7x10308
Decimal Decimal 128 precision floating point number 16 1.0x10−28 to about 7.9x10
Character type Char Char 16-bit Unicode characters, which are placed in the "characters" 2  
Boolean type bool Boolean Indicates true or FALSE 1  
Date Time Datetime Datetime      
Structural body struct Struct      
Enum type Enum Enum      
Reference type String type String String      
Class          
Array          
Collection          

V. Variables, constants

1: Naming rules for variable names:

1.1: Variable name consists of: letter, number, underline, @, Kanji.

1, 2: Initials can only be used with letters, underscores, @, kanji

1, 3: Cannot duplicate keyword

2: Definition of variables:

Data type variable name [= value]; Values within [] may not be written

Example: int a=1;

3: variable name plus keyword (cannot be assigned, only value): const

Example: const int a=1;

Six: Basic type conversions:

1, automatic conversion (implicit conversion)--when converting from a value type to a reference type

2, CAST (explicit conversion)-when converting from a reference type to a value type, or from a floating-point type to an orthopedic

When you convert from a reference type to a value type, you must reference the data element in the type, which can be converted to a value type in the capacity range, otherwise it cannot be transferred.

1>: with ();

Example: int a;double b=12.3;a= (int) b;

2>: with convert;

Example: int A;    float C; Double b=12.3;

A=convert. ToInt32 (b);

C=convert. ToSingle (b);

3>: Using the parse;

Example: int A; Double b=12.3;

A=int.parse (b);

Seven: Operators

Classification

Symbol

Explain

Priority level

Count

++   --

Gaga minus minus

From high to low, that is, the execution order is from top to bottom. (Highest precedence of parentheses)

*/%

Multiplication to take the remainder

+  -

Add and Subtract

Relationship

> < >= <=

Greater than or equal to less than or equal to

==     !=

equals Not equal to

Logic

&&

With (and)

||

Or

!

Non (note: Priority at the top level of this table)

Conditional operators

?:

The only ternary operator if

Assign value

=    +=  -=  *=    /=   %=

such as: X-=4. that is x=x-4;

1. Arithmetic operators:
+ - * / % ++ --
Attention:
1. When doing a division, if two operations are integers, the result after the operation is an integer.
2. When doing arithmetic, if the two operands are not the same type, the type conversion will be done automatically at the time of operation.

Use of% modulus of redundancy
1. Determine if a is a multiple of B (can be divisible) ====>a%b whether ==0
2. Determine if the digits of a are b====>a%10 ==b
3. Turn a number into a number within a range (a theorem that uses the remainder to be larger than the divisor, such as the largest single number in hexadecimal is F (15))

++ --
int a = 5;
int b= a++; ====> can be written as int b =a; A = a+1;
int c = ++a;====> can be written as a = a+1; int c =a;
The result of the operation is
b = 5;
c = 7;
Note: + +-these two operations can only be applied to variables (5++ is not right!!) Constants are also not available!! )

2. Relational operators:
= = = > < >= <=
The result of the relational operator operation is all bool type (the result is either ture or false)

int a = 5;
int B = 6;
Console.WriteLine (A = = B); ====>false
Console.WriteLine (A! = b); ====>true
Console.WriteLine (a > B); ====>false
Console.WriteLine (a < b); ====>true
Console.WriteLine (a >= B); ====>false
Console.WriteLine (a <= B); ====>true

Note: = = cannot be written as = (A = is the meaning of an assignment)


3. Logical operators:
&& | | !
&&====> Two conditions are true, and the result is false otherwise
|| ====> two conditions as long as there is a set, the result is true, two are not set to False
! ====> The original result to the opposite (if it is true, the inverse is false)

4. Other operations
= ====> Assignment operation, assigns the following value to the left variable. (Note: only variables)
+ = = *=/=%= ====> composite Operator (example: A + = B; (meaning a = a +b;))

C#main function

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.