C # basic knowledge class notes,

Source: Internet
Author: User

C # basic knowledge class notes,

2017-08-19

I did not know what to write for the first time, so I shared some basic knowledge about C # programming language I learned for a week. I hope it will be helpful and helpful to everyone, please kindly advise and point out the shortcomings. Thank you !!!

Chapter 1 Development

1. Start with the first code

Computer Language: a tool for communication between humans and computers

Compile: Convert source code into machine code

Compiler: compilation tool

Source code: content written in a computer language

Code: source Code Compile: Compile Run: Run

Public static void Main (string [] args)

{

Console. WriteLine ("hello, world ");

Console. ReadLine ();

}

2. Understand the main function

Definition: the function that runs when the program starts is also called (Main function; start function; entry function)

When a function is running, the program runs every code in the function from top to bottom. After the main function is run, the program ends.

3. Output statement

Definition: output text to the current position of the console. Output from where the cursor is located

Two Writeline output methods:

(1) Console. Write: output text at the cursor position. The cursor does not wrap

(2) The Console. WriteLine outputs the text at the cursor position, and the cursor then wraps the line

Chapter 2 variables and Data Types

1. Data Type: Data Classification and Generalization

Char character type indicates a single character (Chinese characters, letters, numbers, punctuation marks)

Writing Method: Expressed in pair single quotes

String type indicates an unlimited number of characters (male letters, numbers, punctuation marks)

Writing Method: Double quotation marks are used in pairs.

An integer is an integer. It is an integer.

Writing Method: Direct Writing

Double decimal type indicates the number that contains the decimal point

Writing Method: Direct Writing

2. Recognize Variables

Definition: memory space for storing data, and the data content in the memory area can be overwritten.

Variable Declaration: Specifies a memory space for storing data.

Syntax: space variable name of Data Type

Variable assignment: stores data in the memory space of the variable.
Syntax: variable name = data (=: Value assignment)
The variable must be declared first and then assigned a value.

Three elements of a variable: data type, variable name, variable value

3. variable naming

Naming Standard: (1) Hard Standard 1. It must consist of digits, letters, and underscores

2. Cannot begin with a number

3. cannot be the same as the keyword

4. The variable names in the same function must not be the same

(2) soft Standards 1. Variable names should be informed

2. lowercase letters of variable names

4. Tips for using variables

Merge Declaration: declare multiple variables of the same type, which can be completed in one declaration statement.

Initialization upon declaration: Initialize the variable while declaring

5. Data Operations

Number calculation: the process for calculating mathematical expressions supports: (+) plus (-) minus (*) multiplication (/) Division (%) for remainder

String operation: operations on characters and any type support: concatenation (+)

Return type: the data type of the operation result.

6. Input statements

Definition: Get user input in the console

Purpose: Pause the program and wait for user input. After the input, the user's input is obtained and the program continues to run.

Writing format
(1) Console. ReadLine (); // line feed is automatically entered.
(2) Console. Read (); // The input statement does not wrap automatically.
The return type is string.

7. type conversion

Convert any type to string
Conversion Code: "data to be converted". ToString ();
Return type: string

Convert string to double
Conversion code: double. Parse (string to be converted );
Return type: double

Convert string to int
Conversion code: int. Parse (string to be converted );
Return type: int

Convert int or double to string
Conversion code: Data. ToString ();
Return type: string

Convert int to double
Implicit conversion: no additional code is required, and the computer automatically completes the conversion.
Return type: double

Convert double to int
Explicit conversions: additional code is required and the computer does not automatically convert
Conversion format: Two parentheses () are written before the data to be converted, and the target type to be converted is written in ().
Return type: int

The value range of double is greater than that of int.
Convert a numeric type with a small value range to a numeric type with a large value range using implicit conversion
Convert a numeric type with a large value range to a numeric type with a small value range using explicit conversion

8. Common escape characters

\ "Double quotation marks \ 'single quotation marks \ n linefeed \ t tab \ slash

9. digit type

Integer type:

Real Number Type:

Floating Point Number
The maximum number of float Single-precision valid values is 7.
The maximum number of double-precision valid values is 15.


10. Code comments

Definition: Some description statements are used to make your code easier to read and understand. The annotation content does not have any substantive functions and does not participate in compilation. It only exists in the source code.

When to use annotations
Code is hard to understand
Large amount of code
Complex code
Someone else will read your code During Team Development

Single line comment: // comment content multi-line comment:/* multi-line comment start comment content */end

11. software errors and debugging


Compilation error: The Source Code cannot be compiled.

Error found: view the Error List of development tool

Solve the error: make corresponding changes according to the error prompt

Error features: easy to detect and modify

Running error: an error is reported during running.

Error found: Run in debug mode and run the statement to report an error

Solve the error: make corresponding changes according to the error prompt

Error features: Hard to discover and modify

Logical error: the running result is inconsistent with expectation

Error detected: Check the running result carefully to see if it is consistent with the expectation.

Use VS breakpoint debugging to check the execution results of each step

Error features: difficult to find and modify

Now, I hope you can advise me. There will be updates in the future. welcome to join us !!!

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.