Net and C #
• Net (DOTNET ):
-It generally refers to. NET Framework, a platform, and a technology.
• C # (sharp ):
-A programming language that can develop applications based on the. NET platform
• Java:
-Both a technology and a language
What can. Net do?
Desktop Application winform
Internet application ASP. NET
Mobile development WP7
C/S: Client/Server)
B/S: Browser/Server)
. NET development learning path
What is a program?
"Notepad"
Control prepared items
Three statuses
Imitation: code-based writing and Analysis
Simulation: write by yourself according to the steps
Creation: Design on demand
Introduction to Visual Studio
Install and create solutions and projects
Use various forms of Vs and font row numbers
C # source files (classes) generally end with CS
The C # entry function is the main function.
Basic Input and Output statements (DEMO)
Multiple projects and startup items
Project loading and unloading
Comments in C #
When a line comment
// Comment content
Multi-line comment
/* Comment content, nesting not allowed */
Document comment
/// Comment content
Type the data such as methods and classes, // automatically generate
Common basic operations
Common keys (move the cursor)
Copy, paste, and undo
Insert and overwrite Modes
Punctuation
Common F keys: F5, F6, F11, and F1
Collapse code
Variables and common data types
Programs are constantly storing and processing data.
Common data types include
Int, double, decimal, Char, String, bool
Declare the variable type name and variable name;
Store Data
Is the following method correct?
Int A = 3.14;
Variable Declaration
Syntax
Type name variable name;
Variable name = nominal value;
Variable
Declare, assign values, and then use
If you want to declare multiple variables at a time, use commas to separate them.
Possible initial values
Partial initial values
Variable name
Naming rules:
1. It must start with "letter" _ or.
2. It can be followed by any letter, number, or underline.
Note:
1) do not repeat the variable name in the C # system with the keyword.
2) in C #, the case is sensitive.
3) Duplicate definitions of the same variable name are not allowed (so I think it is not rigorous)
Variable names must be meaningful when defining variables.
C # variable naming and code specification-camel (camel, camel) naming method:
The first letter is lowercase, And the other words are uppercase.
Pascal Naming Convention: the first letter of each word is capitalized.
If you use the abbreviation of an English word, use uppercase!
Value assignment operator and value assignment expression
Value assignment operator: =
The formula with the value assignment operator is called the value assignment expression.
It is not the mathematical meaning of "equals ".
No data exists before the assignment. The default value is 0 (unavailable)
You can assign values multiple times. If you assign values, the original values will be lost.
Int num = 2;
Num = 10;
Console. writeline (Num );
Character and string
String strval = literal value;
You can use "+" to concatenate strings.
How can I output it: "C # Getting Started classic" is easy
Common escape characters:
\ N \ r \ B \ t \\\"
@ Indicates that the character is not translated before the string
Demo:
Define a variable to store the customer's name and display it on the screen: "Hello, xx ".
Customer Representative name
The + number can be used to connect two strings. The "+" number indicates the meaning of the connection.
Demonstrate multiple assignment operations
Define a variable to store a person's age (18), and then find that the person's age is not 18 years old, I want to change the age of this person to 20 years old (the variables in this question can be assigned multiple times), and finally output the age of this person to the screen?
Variable exercise
1. define three variables to store a person's name (Zhang San), age (28), and salary (7600.33 ). my name is XX. Today I am X years old, and my salary is XX yuan.
2. Define four variables to store a person's name, gender, age, and phone number. And print it on the screen.
3. output on the screen: my mobile phone is Philips model: 998 price: 1500 Yuan weight: 0.3 kg
Define the value stored in the variable and display it on the screen.
4. Define two variables, for example, a B is assigned to 10 and 5 respectively, and the Write Program exchanges the values of the two variables.
String exercise
1. Exercise: Ask the user what kind of fruit they like to eat. If the user inputs "apple", it will show "Haha, so coincidentally, I also like to eat apple"
2. Exercise: Ask the user to enter the name and display "Hello, XXX". XXX is the name you just entered on the screen.
Method for receiving user input:
Console. Readline ();
Exercise
The price of a T-shirt in a store is 35 RMB/piece, and the price of trousers is 120 RMB/piece. james bought 3 T-shirts and 2 trousers at the store. Please calculate and show how much James should pay?
How much should James pay if the store offers a 8.8 discount for James?
Total purchases: XX yuan, after discount: XX yuan.
Integer type
Type |
Other names |
Allowed value |
Sbye |
System. sbye |
In-128 ~ Between 127 |
Byte |
System. byte |
From 0 ~ Between 255 |
Short |
System. int16 |
In-32 768 ~ Between 32 and 767 |
Ushort |
System. uint16 |
From 0 ~ Between 65535 |
Int |
System. int32 |
In-2 147 483 648 ~ Between 2 147 483 647 |
Uint |
System. uint32 |
From 0 ~ 4 294 967 295 |
Long |
System. int64 |
In-9 223 372 036 854 ~ Between 9 223 372 036 853 |
Ulong |
System. uint64 |
From 0 ~ 18 446 744 073 709 551 615 |
Floating Point Type
Type |
Other names |
Minimum M Value |
Maximum M Value |
Minimum value of E |
Maximum Value of E |
Approximate minimum value |
Approximate Maximum Value |
Float |
System. Single |
0 |
224 |
-149 |
104 |
1.5 × 10-45 |
3.4 × 1038 |
Double |
System. Double |
0 |
253 |
-1075 |
970 |
5.0 × 10-324 |
1.7 × 10308 |
Decimal |
System. Decimal |
0 |
296 |
-26 |
0 |
1.0 × 10-28 |
7.9 × 1028 |
Its class type
Type |
Class |
Allowed value |
Char |
System. Char |
A unicode character, which is stored in 0 ~ Integer between 65 and 535 |
Bool |
System. Boolean |
Boolean value: true or false |
String |
System. String |
A group of characters |
Arithmetic Operators-automatic type conversion
What is the output result of the following code?
Int A = 10, B = 3;
Int mod = A % B;
Double quo = A/B;
Console. writeline (MOD );
Console. writeline (quo );
Automatic type conversion rules
The operands involved in the calculation (arithmetic operation and value assignment operation) must be consistent with the result type. when the following conditions are met, the system automatically completes the type conversion.
Two types of compatibility
For example, int and double are compatible.
The target type is greater than the source type.
Example: Double> int
For expressions
If an operand is of the double type, the entire expression can be upgraded to the double type.
For example, the exercise questions with a 8.8 discount.
If you want to calculate 10/3 For the remainder, you need to get 3.333 for processing.
Forced type conversion
In the above question, after 8.8 off, a decimal number occurs. For the convenience of settlement, the store only collects the user's integer part of the money. For example, if the user is 166.78, only 166 yuan is collected. What should I do?
Syntax:
(Data Type name) value to be converted;
For example:
Int B = (INT) 3.14;
Forced type conversion, data types must be compatible
2. Variable names start with "_", lowercase letters, and @"
3. escape characters :\
\ N newline \ r carriage return \ B backspace \ t tab \ r \ n is equivalent to carriage return
@ Do not escape the string
/* @ Can also be used for line-breaking processing strings */
/* @ "C #" "good and simple" the output is "C #" good and simple */
4. type conversion
Int num = int. parse ("string ");
5. Constant: const
Enumeration (type): Enum
// Enum sex {male, female}
// In the main function, the enumerated variable is defined. Sex S = sex. Male;
// Enumeration is of the int type. Note the strong conversion of (INT) s when outputting an integer.
// If the enumerated type is converted into a string:
(Self-defined enumeration) (enum. parse (typeof (self-defined), "string to be converted "));
That is:
String STR;
S = (sex) (enum. parse (typeof (sex), STR ));
Output: Remember S. tostring ();