C #,
C # Cross-language and java cross-platform
C # is an object-oriented language
Three basic features of object-oriented architecture:
1. Encapsulation
2. Inheritance
3. Polymorphism
Output line breaks
Console. write ();
Output line feed
Console. writeLine ();
Non-printable characters
Space
\ T tabulation
\ N line feed
\ 'Single quotes
\ "Double quotation marks
Data Type
1. Value Type
Integer: short, int, long
Float: float (single precision) and double (double Precision)
Boolean Type: bool
Enumeration: enum
2. Reference Type
Character Type: char, string
Class: class
Interface: interface
Array: []
Object
Note:
The default decimal point is double. If the float type is used, add f after the decimal point.
Bool has only two values: true and false
The char value must use '', and the string value must use ""
Variable name naming rules:
Other letters
Letter _ letter _ number
For example:
Age
Other letters
A ge
Variable
Definition:
A bucket whose internal values can be changed
Features:
The value of the bucket can be changed by value assignment.
For example:
Int age = 10; // value assigned when declaring
Age = 11; // assign a value again
The last age value is 11.
Syntax:
One statement at a time:
Data type variable name;
For example:
1) string name;
2) int age;
Multiple declarations of the same type at a time:
Data type variable name 1, variable name 2;
For example:
1) string name1, name2;
2) int num1, num2, num3;
Assignment:
1. assign values when declaring
For example:
1) string name = "ccliu ";
2) int num1 = 15, num2 = 30;
2. Declare and assign values
For example:
1) string name; name = "ccliu ";
2) int num1, num2;
Num1 = 15; num2 = 10; // values are not the same
Num1 = num2 = 10; // same value assignment
Constant
Definition:
Storage space whose internal values cannot be changed
Features:
After the bucket is declared as a value, the value cannot be changed.
Syntax:
Const data type name = value;
For example:
Const double PI = 3.1415;
Note:
1) The constant name must be capitalized.
2) constants must be assigned values during declaration.
3) The constant value cannot be changed.
Input:
Function: Console. ReadLine () is used to receive a line of strings entered by users on the Console.
Syntax:
Console. ReadLine ();
For example:
The syntax for receiving string types is as follows:
String name = Console. ReadLine ();
The syntax for receiving integer types is as follows:
Int age = Convert. ToInt32 (Console. ReadLine ());
Receive Double Precision Floating Point
Double money = Convert. ToDouble (Console. ReadLine ());
Type conversion:
1. Display conversion (forced conversion)
1) Convert. ToXXX (any data type); // the first type is recommended.
2) XXX. Parse (string data );
Int money = (int) 3.14;
Int money = Convert. ToInt32 (3.14 );
Int money = int. Parse (3.14 + "");
2. implicit conversion (default conversion)
Char short int long float double
Note:
1) char cannot be implicitly converted to short
2) implicit conversion from left to right (default conversion)
3) display conversion from right to left (forced conversion)
Operator
()
RMB 1
++ --! (Non-logical)
Binary
Computing
First */% +-
Off
First >>=<=then =! =
Bytes
First & (logical and) | (logical or)
Assign
First * =/= % = + =-=
Sanyuan
Expression? Value 1: Value 2
Receive user input:
// Receives user input numbers
Int num = Convert. ToInt32 (Console. ReadLine ());
// Receives decimals from users
Double money = Convert. ToDouble (Console. ReadLine ());
// Receives user input strings
String name = Console. ReadLine ();
// Receives user input characters
Char ch = Convert. ToChar (Console. ReadLine ());