. NET basic step by step: [Comments, naming rules, access modifiers, data types, constants, variables],. net naming rules

Source: Internet
Author: User
Tags variable scope

. NET basic step by step: [Comments, naming rules, access modifiers, data types, constants, variables],. net naming rules
Annotations, naming rules, access modifiers, data types, constants, and variables

One can't be written.NoteProgram ape is not a good product, we will start from the notes.

There are three annotations in C:

  • First, the single line comment starts with //, followed by the comment content

-// Single line comment

-

 

  • Type 2: Comments starting with/*/end with comments

-/**/Multi-line comment

-

 

  • Third: a document comment input a line in the method or class // will generate

-///

-/// Document comment

-///

-

 

So .... This is the usage of the three annotations.

 

Let's talk about it again.Naming rules:

-1It must be a letter "_Or @Start with a symbol .--Do not start with a number

-2It can be followed by any letter, number, or underline.

-3 CamelNaming Method: Lowercase for the first word and uppercase for the other words.

-4 PascalName:The first letter of each word is capitalized.

-If you use the abbreviation of an English word, use uppercase!

-Note:

-1) The variable name you set should not be the same as c #The keywords in the system are repeated.

-2) In c #Medium,It is case sensitive.

-3)The same variable name cannot be defined repeatedly

 

Let's talk about the access modifier in C #: [I will ask during the interview]

Access Modifier

Description

Public

Public access. Not limited.

Private

Private access. Only access by members of this category is allowed.

Protected

Protect access. The instance cannot be accessed only by the class or subclass.

Internal

Internal access. It is restricted to access within the project, and others cannot be accessed.

Protected internal

Access is protected internally. Only access to this project or subclass is allowed.

 

* In C #, the default access modifier is internal.

 

Let's talk about the data types in C:

Basic Data Type basic data type: Value Type and reference type.

The two basic data types are packed and unpacked.

Packing: Convert the value type to the reference type.

Binning: converts a reference type to a value type.

The code for packing and unpacking is as follows:

 

Value Type: data type, structure, and enumeration except string.

Reference Type: string, class, abstract class, interface, set, Delegate, event.

The difference between the value type and the reference type:

*Value TypeThe value is stored inMemory Stack.

*Reference TypeThe value is stored inMemory heap.

*When copying a value type, the value itself is passed.

* When copying a reference type, the object is referenced.

Okay, the basic data type is finished. Let's talk about several common data types:

Float: float

Int: integer, with a 32-bit symbol. It can only store integers and decimal places.

Bool: Boolean

Byte: unsigned, 8-bit

Short: signed, 16-bit

Long: signed, 64-bit

String: string, used to store multiple texts, or to store null values. string-type values need to be enclosed by double quotation marks.

Char: a single character. It can contain at most one character and cannot be empty.

Double: decimal point. It can store both integers and decimals. The number of digits after the decimal point is 15 ~ 16-bit

* Here I want to talk about the string data type separately, which hasImmutable,That is, after you assign a value to a string, the old value is not destroyed, but a new space is created to store new values.

After the program ends, GC scans the entire memory. If it finds that some space is not pointed to, it will be destroyed immediately. [Interview Questions]

 

Since there is a data type, conversion of the data type is involved, and conversion of the strong conversion and implicit conversion (automatic type conversion) and display conversion are involved in the conversion:

We require that the numbers involved in the operation be of the same type. If they are inconsistent, automatic type conversion will occur if the following conditions are met, orImplicit type conversionThe opposite is the display type conversion.

Condition:Int And Double Compatible(All are numeric)

IntConvertDoubleSmall to largeIs implicit type conversion

DoubleConvertIntLarge to smallYesDisplay type conversion

If the type is compatible with two variables, you can use automatic type conversion or forced type conversion. However, if the two types of variables are not compatible, such StringAndIntOrString AndDoubleIn this case, we can useConvert.

Note:: UseConvertTo perform type conversion, you also need to meet a condition that you must go through. (That is, the type you want to convert cannot be incredible)

 

Now we have made a lot of preparations, and we can finally use them:

 

C #Constant in: As the name impliesThe amount that will not be modified.

Key words defining constants:Const

Syntax: access modifier const data type constant name

Example: public const int age

Value assignment: public const int age = 20;

Usage rules of constants: If you use constants, you must declare them before assigning values.

C # VARIABLES:As the name implies, it is the variable amount.

Syntax:Access modifier data type variable name;

For example:Public int age

Value: public int age = 20;

Usage rules of Variables: If you use a variable, you must declare it before assigning values.

Variable scope:

The scope of a variable is the scope that you can use.

The scope of a variable generally starts from the brackets that declare it to the ending brackets corresponding to the brackets.

Within this range, we can access and use variables. The access fails if the access exceeds this range.

 

By the wayVS IDESome tips, such as wavy lines:

Wavy line:

1)If a red line appears in your code, it means a syntax error occurs in your code.

2)If there is a green ripple in your code, it means that your code syntax is correct.

*It only prompts you that there may be errors, but it may not necessarily be errors, or warnings, or you may haveVS IDEIf you have any questions, try restarting the system.

 

Now, the comments, naming rules, access modifiers, data types, constants, and variables of today are all here.,I hope it will help beginners. I also hope that the great gods will take us with us, pack us with force, and fly us with us...

Finally, make a small advertisement: QQ group:. NETStep by stepOne ScreenGroup Number:590170361(Add group remarks: what you see in the blog Park)

 

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.