C # Study Notes

Source: Internet
Author: User
C # Study Notes (1): Data Type
C # There are two types of data: numeric and reference;
I. numeric types include integer, numeric, Boolean, floating point, decimal, structure, and enumeration.
1. Integer type: byte, sbyte, short, ushort, Int, uint, long, ulong, commonly used int;
2. floating point type: float and double;
3. Decimal type: dicemal;
4. Character Type: Char;
5. boolean type: bool;
Ii. reference types include: String, array, object type, class, interface, proxy
1. Object Type: object;
2. string type: string;
Iii. Initial Value assignment
Iv. type conversion: implicit conversion and explicit conversion; Package conversion and package splitting Conversion
1. implicit conversion: converts a low-level data type to an advanced data type and the result is an advanced data type;
2. explicit conversion: Cast)
3. Package conversion and package splitting conversion: The difference between heap and stack;
V. simple numeric type
1. Two domains: maxvalue and minvalue;

C # learning notes (2): operators and expressions
1. Arithmetic Operators
1) ++, -- differences between variables
2) Negative OPERATOR: for example,-3 +-3 is equivalent to-3-3
2. logical operators
3. Relational operators
4. Other operators
1) is Operator: X is int
2 )? : Operator:
3) as operator:
Object x = 5.4f;
Object y;
Y = x As float;
4) typeof OPERATOR:
5. Checked and unchecked

C # Study Notes (3): Selection and loop structure
1. If statement
1) if (...)
2) if (...) else
3) if (...)
Else if (...)
Else if (...)
Else
Note the nested judgment statement. Starting from the inner layer, else is always paired with the if statement that is not paired at the top of the nested judgment statement.
2. Switch statement
Switch (...)
{
Case ...:
Case ...:
...
Default:
}
3. While statement
While (...)
{
....
}
4. Do-while statement
Do
{
...
}
While (...)
5. For statements
For (...;...;...)
{
...
}
6. foreach-in statement
Foreach (... in ....)
{
.....
}

C # Study Notes (4): Array
1. One-dimensional array
1) int [] intarray = new int [10];
2) int [] intarray;
Intarray = new int [10];
3) int [] intarray = new int [10] {1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
Note: initialization of some elements is not allowed. All elements must be initialized.
2. Multi-dimensional array
1) int [,] intarray = new int [3, 2];
2) int [,] intarray;
Intarray = new int [3, 2];
3) int [,] intarray = new int [3, 2] {0, 1}, {1, 2}, {2, 3 }}
3. nested Array
Int [] [] intarray = new int [2] [];
Intarray [0] = new int [2];
Intarray [1] = new int [3];
4. system. array class
1. Attributes
Length
Rank
2. Method
Sort reverse
Indexof lastindexof

C # Study Notes (5): Object-oriented and class
Object-oriented
1. Data encapsulation
2, Code Reuse
3. Polymorphism
4. Heavy Load
Namespace
Using [alias =] namespace;
Declare your own class
1. encapsulate data
Private int count;
......
2. Structure and Analysis
Construction: public class name (...) {...}, multiple
~ Class Name: structure, generally not required
3. Method
Use your own class
Domain
Static domain: public static int field1;
Read-Only domain: Public readonly int field1;
Attribute
Modifier type identifier {code}
Private string name;
Public string name
{
Get {rerurn name ;}
Set {name = value ;}
}
Index
Modifier type this [index value]
Private int [] array = new int [5];
Public int this [int Index]
{
Get
{
Rerurn array [Index];
}
Set
{
Array [Index] = value;
}
}
Heavy Load
The key is that the parameters are different.
Params: Other parameters are not supported. Therefore, it is generally the last parameter.
Ref and out: the ref and out keywords must be added before the real parameter. The difference between ref and out is that the out keyword does not require the real parameter to be initialized in advance.
Operator overload
Syntax: public static return type Operator (parameter) {code}
Data conversion can also be overloaded.
Syntax: public static implicit operator type after conversion (converted value)
Public static explicit operator converted type (converted value)

C # Study Notes (6): Inheritance
Initial inheritance
1. Derivation:
The inherited classes are called base classes and parent classes. The inherited classes are derived classes and child classes.
Class subclass name: parent class name
{
.....
}
Sub-classes can overload the methods of the parent class. Pay attention to different row parameters.
When constructing a new object in a subclass, you must call not only the constructor of the subclass, but also the constructor of the parent class. Also, the called constructor must have a list of corresponding parameters.
2. Base keywords
Child classes can use various members of the parent class, but child classes can only use members declared as public and protected in the parent class.
The base keyword is used to replace the name of the parent class in the subclass.
3. Prohibit inheritance
The concept of a closed class: sealed
Sealed keywords can be used not only to declare classes, but also to declare methods and attributes of "closed ".
4. access protection
Protected Keyword: Visible only on the inheritance tree chain of the class
5. Internal access
Internal Keyword: visible inside an assembly
6. member access level
PRIVATE: the private member can only be used in the class of the declared member.
Protected internal: The member can only be used in the same class and its subclass, and all
Internal: Access in an assembly
Protected: can only be accessed on the class inheritance tree chain
Public: unrestricted
Polymorphism and Virtual Member
1. Use the virtual keyword in the parent class to declare virtual members. Virtual members can be class methods, attributes, and indexes, and cannot be domain or private member variables.
2. Use the override keyword in the subclass to re-declare the virtual member.
Abstract class
1. abstract keywords
2. the abstract method cannot instantiate any code for it. During method declaration, it cannot be used after the method {};
3. Abstract attributes must indicate the get or set parts of the attributes, but no code can be instantiated;
Shape
Only child classes of the parent class can be used.

C # Study Notes (7): interfaces and Proxies
Interface
1. interface declaration
1) Syntax: [modifier] interface name [: parent interface name] {code };
2) key points:
A. When declaring an interface member, you cannot specify any access modifier for the interface member;
B. Do not instantiate any code for a member
2. Use of interfaces
1) An interface can only be implemented through class inheritance.
2) subclass not only inherits from the parent class, but also from the interface
3) after a class inherits from the interface, all the members of the parent interface must be instantiated in the subclass.
3. Comparison between interfaces and abstract classes
1) The domain or private variable cannot be declared in the interface.
2) You cannot use any access modifier when declaring an interface member.
3) once an interface is inherited, all the Members must be instantiated in the subclass, while the abstract class can overload some members as needed.
4) the interface allows multiple inheritance
5) the interface has a higher abstraction level than the abstract class.
4. common interfaces of the system namespace
1) icloneable: Clone Method
2) icomparable: compareto Method
3) iconvertable:
4) iformatable: Format Method
Proxy
1. proxy statement
[Modifier] delegate return type proxy name (parameter list );
2. Proxy usage
Create a proxy object using the new operator and specify the referenced method name for the proxy object.
3. system. Delegate class
Method and target attributes
4. Events
Identifier of the Event Type
Modifier event type identifier {Get {}; set {};}
To declare and use an event, follow these steps:
1) create a proxy or use the system Proxy: eventhandler
2) declare an event using the event keyword inside the class and define the method for calling the event in the class.
3) declare multiple methods and event associations

C # study notes (8): Structure and enumeration
Structure
1. Structure Declaration
[Modifier] struct structure name [: interface name] {code };
A constructor without parameters is not allowed in the structure.
2. Structure usage
1) Point P1 = new point (1, 1 );
2) Point P1;
3. Differences between structures and Classes
1) structure cannot be inherited
2) A constructor without parameters cannot be declared in the structure.
3) an initial value cannot be assigned to an instantiated domain in the structure.
4) when the object is declared using the structure type, the new operator is not used.
5) The structure is a numerical type, and the class is a reference type.
Enumeration
1. Enumeration Declaration
[Modifier] Enum name [: Various integer types] {list };
Example: Public Enum test: ulong {main = 1, max = 2 };
2. Use of enumeration
Explicit type conversion is required to convert data of the enumerated type to an integer value.
3. system. Enum class
1) format Method
2) fromstring Method
3) getname and getnames Methods
4) getunderlying Method
5) getvalus Method
6) isdefined Method
7) toobject Method

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.