[C# Learning] C# Basics

1. Symbol

1) Notes

① line comment //

In VS2013, quick comment, uncomment:Annotation shortcuts

②Block comment /**/

③ paragraph comment ///

Segment comments are automatically prompted for future use.

/// <summary>  
///  
/// </summary> 

2) Expand and collapse code blocks

#region
#endregion

2, special operators;

1) The is operator is
used to check whether the variable is of the specified type. Return true/false. Such as:

bool result =  i is int;

2) Conditional operator (?:)
Condition is true, evaluate expression 1, otherwise evaluate expression 2.
3) typeof operator
Get the type (Type object) of the system prototype object.

static void Main(string[] args)
        {
            Type mytype = typeof(int);
            Console.WriteLine("类型:{0}",mytype);
            Console.ReadLine();
        }

operation result:result

3, char type:

Represents a Unicode character in C#.

4. Escape characters:

\ddd Characters represented by 1~3 octal digits
\xhh Characters represented by 1~2 digits in hexadecimal

5. Programming specification:

1) Data type shorthand rules:
String: str; Boolean: bl; Short: sint; Long: lint; Single-precision floating-point: flt; Double-precision floating-point: dbl; Byte: bt
2) Variable naming rules:
Module level: M_int_name; Global: G_int_name; Local: P_int_name
3) Constant naming rules:
Module level: Mc_int_name; Global: Gc_int_name; Local: Pc_int_name
4) Class naming rules:
a. Use nouns.
b. Not prefixed with C or underscore
c. Avoid custom exception classes, which end with Exception.
d. Do not assign a value of Null to the initialization class.
e. Avoid including multiple namespaces in a class file.
5) Attribute naming rules:
a. Use nouns and do not repeat with class names.
b. Replace public and protected member variables with attributes.
6) Method naming rules:
a. Verb, table behavior.
b. When there are more than 5 parameters, consider using struct to pass multiple parameters.
7) Interface naming rules:
a. Prefix I, use adjectives (because it is to add a certain capability to the class)
b. Contains 3 to 5 members. No more than 20 members.
c. Avoid member inclusion events. why?
d. Replace abstract methods with interfaces.
e. Use the interface implementation shown.
8) Database naming convention:
a. Beginning with db_ + database full name/abbreviation
b. Data table: tb_.
c. View: view_.
d. Stored procedure: proc_
e. Trigger: trig_

6. Method modifiers

1)private

Private members can only be accessed by classes and structs that declare them.

2)public

3)protected

Protected members are accessible in its class, derived classes.

4)internal

Internal types are accessible in files in the same assembly.

5)partial

Partial classes and structures are defined throughout the same assembly.

6)new

7)static

8)virtual

9)override

Provides new implementations of virtual members inherited from base classes.

10)sealed

This class cannot be inherited from a
sealed class.

11)abstract

The class can only be the base class of other classes.
abstract class.

12) external

Implement methods externally.

7. Function

1) Constructor

2) Destructor (destructor)

The destructor is the opposite of the constructor. When the object leaves its scope (for example, the function in which the object is located has been called), the system automatically executes the destructor. The destructor is often used to do the work of "cleaning up the aftermath" (for example, a memory space is opened up with new when creating an object, and it should be released with delete in the destructor before exiting).
The destructor name should also be the same as the class name, just add a tilde ~ in front of the function name, such as ~stud( ), to distinguish it from the constructor.
Destructors cannot take any parameters and have no return value (including void type).
There can only be one destructor and cannot be overloaded.
If the user does not write a destructor, the compilation system automatically generates a default destructor, which does nothing.

3) Virtual function

If an instance method is declared with the virtual keyword before it, the method is virtual.

The biggest difference between virtual methods and non-virtual methods is
that the implementation of virtual methods can be replaced by derived classes, and this replacement is achieved through method rewriting.

Characteristics of
virtual methods: static, abstract, or override modifiers are not allowed before virtual methods.
Virtual methods cannot be private, so the private modifier cannot be used.

Compared with java

1) Classes only support single inheritance, and interfaces support multiple inheritance. (same as java)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325534458&siteId=291194637