Although C # has been used for so long, I don't know why it is used. Therefore, we decided to continue to consolidate the organization foundation ~~~
1.STACK:Stack is a memory array.
2.Heap:Heap is a memory area.
3.Value Type:Stored in the stack.
4.Reference Type:The storage is in the heap.
5.Class:Class is a class that can store data and executeCodeData structure.
6.Method:
/*****************
The method is an executable code block with a name. You can use the method name to execute code from another place, or pass data into the method and accept data output.
The method has two main parts,Method HeaderAndMethod body.
Method HeaderSpecifies the features of a method and whether the method returns data. If yes, what type is returned.
Method bodyStatements that contain executable code.
*****************/
7.Access modifier:
/*****************
Public: public,SameProgramAny other code in the set or other assembly that references the Assembly can access this type or member..
PRIVATE: private,Only the code in the same class or structure can access this type or member..
Internal: internal,Any code in the same assembly can access this type or member, but the code in other assembly cannot..
Protected: protected,Type or member that can be accessed only by the code in the same class or structure or derived class.
Protected internal: protected internal,Types or members that can be accessed by any code in the declared assembly or a class derived from another assembly.Access from another assembly must occur in the class declaration. The class declaration is derived from the class that declares protected internal elements and must occur through an instance of the derived class type.
*****************/
8.Naming parameters:
/*****************
The location does not need to correspond to the corresponding parameter location one by one. You can use the following method to define the location at any location.
For example:
Int I = M. Call (C: 1, B: 2, A: 1 );
Public int call (A, B, C)
{Return A + B + C ;}
*****************/
9.Static attributes:Yes. No matter whether the class has an instance or not, when accessing from outside the class, you must use the class name instead of the Instance name.
10.Instance constructor:
/*****************
An instance constructor is a special method that is executed when each new instance of the class is created.
The constructor is used to initialize the status of a class instance (first executed when a class object is new ).
*****************/
11.Constructors with parameters:
/*****************
Constructors can include parameters and can be overloaded.
Class C
{
Int ID;
String name;
Public C () {id = 7777; name = "XXX ";}
Public C (INT Val) {id = val; name = "XXX ";}
Public C (string name) {name = Name}
Public void write ()
{Console. writeline ("ID: {0}, name: {1}", name, ID );}
}
Class P
{
Static void main ()
{
C x = new C (),
Y = new C (5257 ),
Z = new C ("Qiqi ");
X. Write ();
Y. Write ();
Z. Write ();
}
}
Output result:
ID: 7777, name: XXX
ID: 5257, name: XXX
ID: 0, name: Qiqi
*****************/
* RandomFunction:
/*****************
Random. Next () returns a non-negative random number;
Random. Next (INT) returns a non-negative random number less than the specified maximum.
Random. Next (INT, INT) returns a random number within the specified range.
*****************/
12. This Keyword:
/*****************
ThisThe keyword used in the class is a reference to the current instance.
The member used for the partition classification and local variables or parameters.
The real parameters used to call the method.
*****************/
12. Hide the base class members:
/*****************
Although a derived class cannot delete any member it inherits, it can hide them.
To hide an integrated data member, you must declare a new member of the same type and use the same name.
Let the compiler know that you are intentionally hiding inherited members and use the new modifier.
You can hide static members.
*****************/
* Generic example:
/*****************
Using system; using system. collections. generic; using system. LINQ; using system. text; namespace consoleapplication1 {class mystack <t> {T [] stackarray; int stackpointer; Public void push (t x) {If (! Isstackfull) {stackarray [stackpointer ++] = x ;}} public t POP () {return (! Isstackempty )? Stackarray [-- stackpointer]: stackarray [0];} const int maxstack = 10; bool isstackfull {get {return stackpointer >=maxstack ;}} bool isstackempty {get {return stackpointer <= 0 ;}} public mystack () {stackarray = new T [maxstack];} public void print () {int I = StackPointer-1; while (I> = 0) {console. writeline ("value: {0}", stackarray [I]); I --;} console. readline () ;}} class program {static void main (string [] ARGs) {var stackint = new mystack <int> (); vaR stackstring = new mystack <string> (); stackint. push (3); stackint. push (5); stackint. push (7); stackint. print (); stackstring. push ("fanxing are great"); stackstring. push ("Hi There"); stackstring. print ();}}}
*****************/
* Extension Method example:
/*****************
View code
1 Public Static Class Helper 2 3 { 4 5 Public Static String Md5hash ( This String S) 6 7 { 8 9 Return System. Web. Security. formsauthentication. hashpasswordforstoringinconfigfile (S, " MD5 " ); 10 11 } 12 13 14 15 Public Static Bool In ( This Object O, ienumerable B) 16 17 { 18 19 Foreach ( Object OBJ In B) 20 21 { 22 23 If (OBJ = O) 24 25 Return True ; 26 27 } 28 29 Return False ; 30 31 } 32 33 } 34 35 36 37 // Call Extension Method 38 39 Console. writeline ( " 123456 " . Md5hash ()); 40 41 Console. writeline ( " 1 " . In ( New [] { " 1 " , " 2 " , " 3 " }));
Many times we needCLRType to perform some operations, but cannot be extendedCLRType method. Only someHelperMethod, or generate a subclass. The expansion method makes these requirements come true.LINQ. You must note that the extension method can only be defined in the static class and is a static method. If the extension method name conflicts with the original method name, the extension method will become invalid. From [http://www.cnblogs.com/lovecherry/archive/2007/08/14/855681.html]
*****************/