[C #4.0 graphic tutorial] Notes (Chapter 2 ~ Chapter 2)

Source: Internet
Author: User

1 .. NET Framework. the. NET Framework consists of three parts (strictly speaking, only the (framework class library). The execution environment is called CLR (Common Language Runtime Library), which manages program execution at runtime. the BCL (base class library) is. NET Framework uses a large class library. it contains the following general basic classes, collection classes, threads and synchronization classes, and XML classes. 2. compile the code into cilcel (Common intermediate language): once it is compiled into the cost machine code, the CLR manages it at its run time, such as releasing the primary memory and checking the array boundary, check for task types and Management exceptions. 3. managed code and unmanaged code: code that is not controlled by CLR, such as WIN32 C/C ++ DLL, is called unmanaged code 4. CLRCLR is. the core component of the. NET Framework. It is at the top of the operating system and is responsible for managing programs and executing them. CLR also provides the following services: automatic spam security and authentication. Access to BCL provides a wide range of programming functions, including WEB services and data services. 5. CLICLI (basic structure of public languages) is a set of standards that take all.. NET Framework components are linked into a cohesive, consistent system. it demonstrates the concept and architecture of the system. it also details the rules and conventions that all software must adhere. CTS and CLS are important components of CLI. 1. the identifier and keyword are case sensitive. Note that @ character 2. output syntax eg: Console. writeLine (,) 3. note 1. there are 16 pre-defined types, of which 13 are simple types. 3 is not simple type decimal: The valid number of decimal type is 28-bit dynamic: Use 2 when using a dynamic programming language. there are six types of user-defined types that can be created by the user. they are 3. the running program uses two memory areas to store data: the stack and stack are a memory array, and the data structure heap of a lifo (first-in-first-out) is a memory area, a large block of memory can be allocated in the heap to store certain types of data objects. 4. the value type and reference type value type only require a separate memory for storing actual data. the reference type requires two segments of memory: the first segment stores the actual data, which is always in the heap; the second segment is a reference, pointing to the location where the data is stored in the heap. for any object of the reference type, all its data members are stored in the heap, whether they are value type or reference type. 5.C# Category 6. static type and dynamic keyword static type: the variable type is determined during compilation and cannot be modified during runtime. dynamic Keyword: represents a specific, actual C # type. It knows how to parse itself at runtime, that is, it is a dynamic static type. 7. you can create a value type that can be marked as valid or invalid, so that you can determine the validity of the value before using it. A common value type is called a non-empty type. ① create an empty type. For example, int.MyNInt; 1. to allocate memory for data, you need to use the new operator to allocate memory for actual data. the new operator allocates and initializes memory for any specified type of instances. it allocates resources from stacks or stacks based on different types. 5 types of access modifiers 1. fields usually store data related to the object status. local variables are usually used to save local or temporary computing data. 2. the var keyword var is not a special type of symbol. It is just a stenographer, indicating any type that can be inferred from the right of the initialization. some important conditions of the var Keyword: ①. ②. it can only be used when the variable Declaration contains initialization; ③. once the editor deduce the type of the variable, it is fixed and cannot be changed. 3. two features of the local constant keyword const: ①. constants must be initialized in the Declaration. constants cannot be changed after declaration. ③. it can only be declared in the class declaration. ④ constants do not have their own storage locations, but are replaced by the compiler during compilation. similar to the # define value eg in C ++:

Int
4. the return value has been tested and declared that a return type method must use the return statement to return a value from the method. The return type should be consistent with the declared return type or can be implicitly converted. you can use the void declaration method for methods that do not return type. return; this type of return statement without parameters can only be used to declare void methods. 5. when reference parameter ① is used as a reference parameter, ②, if it is a reference type variable, you can assign a value to a reference or null value. ③ The reference parameter uses the same memory, while the value parameter does not use the same memory. eg: Process: 6. output parameter keyword out ① the modifier must be used in both the Declaration and call, and the output parameter modifier is out. ② real parameters must be variables. ③ In a method, the output parameter must be assigned a value before it is read, which means that the initial value of the parameter is irrelevant and there is no value for the real parameter before the method call like ref. eg: Process: 7. ① It allows zero or multiple real parameters to correspond to a special form parameter. ② there can be only one parameter array in a parameter list. ③ If yes, it must be the last one in the list. ④ When declaring the parameter array, you must use the params modifier before the data type, and place a group of empty square brackets after the data type. the params modifier is not allowed during the call. ⑤ method call of the parameter array. A comma can be used to separate the list of elements of this data type, or a one-dimensional array of this data type element. ⑥ when the real parameter is a one-dimensional array, the editor uses this array instead of creating a new one. eg: list for real parameters; process: eg: Array for Real parameters 8. summary of parameter types 9. A Method overload class can have more than one method with the same name. This is called a method overload. Each method with the same name must have a signature different from other methods, which can be: ● method name; ● number of parameters; ● data type and sequence of parameters; ● parameter modifier; Note: 10. the named parameter starts from C #4.0. As long as the parameter name is explicitly specified, real parameters can be listed in any order in the method call. eg: use the name parameter structure. For example, if the order of parameters is different, an error is returned when the name parameter is used.
Partialclass: System. web. UI. page_Load (sender, e) my = (); a = my. s (B: 4, a: 4); s (a, B) s = 0; s (B, a) s = 0; s;
11. an optional parameter is an optional parameter that can be included when a method is called or ignored. optional parameters can only be value parameter type. For example: 1. static Field/static member keyword static field is shared by all instances of the class, and all instances access the same memory location. the instance cannot access static members because the static members do not belong to a certain object and only belong to the class itself. 2. attribute attribute is a function member that does not allocate memory for data storage. It executes code. the attribute is a set of two matched methods called accessors. set accessors are used to assign values to properties. get accessors are used to set values from attributes. attribute can also be declared as static. like all static members, the accessors of static attributes cannot access instance members of the category. They exist no matter whether the class has instances or not, and must be referenced by the class name when accessing from outside the class. 3. constructor 4. static constructor ①. use the static keyword ② In the static constructor declaration. ③. the static constructor cannot have an access modifier. ④. 5. object initialization eg: 6. the action of the destructor to clear or release unmanaged resources before the class instance is destroyed. each class can have only one destructor. the Destructor only takes effect on the instance of the class, so there is no static destructor. you cannot explicitly call the destructor in the code. generally, this parameter is not used, and the performance is 7. the implementation of Dispose in the class is called the IDisposable interface. The interface encapsulates the resource cleanup code in a void-type non-parameter method, that is, the Dispose () method. because Dispose is used for cleaning, rather than destructor, it should be called.) This method tells CLR not to call the destructor of this method because it has been cleared. as follows: 8. similar to the const modifier, the value cannot be changed once set. however, there is a difference ① a const field can only be initialized in the declaration statement of a field, while a readonly field can set its value at any of the following places. ● In the field declaration statement, this is the same as any const ● class constructor. if it is a static field, initialization must be completed in the static constructor. ② The value of the const field must be determined during the compilation period, while the value of the readonly field can be determined during the runtime. the added flexibility allows you to set different values in different environments or constructors. ③ unlike const, const is always static. For the readonly field, it can be an instance field or a static field. it also has a storage location in the memory. eg: 9. this keyword is used in the class to reference the current instance. it can only be used in the code blocks of the following class members. ● instance constructor ● instance method ● instance accessors of attributes and indexes cannot be used in any static member. this is used for the following purposes: ● used for partition classification members and local variables, or parameters; ● used as real parameters for calling methods. 10. an index is a set of get and set accessors, similar to attribute accessors. there is no name for the index, and the name location is the keyword this. the parameter list is in the middle of square brackets. at least one parameter index must be declared in the parameter list and can be reloaded. The indexes that are reloaded in the class must have different parameter lists. eg:
Class Lastname; FirstName; CityOfBirth; [index] (index) 0: Lastname =; 1: FirstName =; 2: CityOfBirth =;: (); (index) 0: lastname; 1: FirstName; 2: CityOfBirth ;:();
11. the partial class and the partial type keyword partial. The declaration of each partial class contains the declaration of some class members. the partial class declaration of a class can also be in different files in the same file. example of the division method: 1. hide the base class members and use the new keyword to explicitly tell the compiler to mask the base class members. however, if you want to access a hidden base class member, you can use the base expression to access it. 2. if a base class is referenced by a derived class object, you can obtain the reference of the base class of the object and convert the reference to the base class type using the type conversion operator. eg: 3. when the base class reference is used to access a derived class object, the base class member is obtained. the virtual method can use the reference of the base class to access "Rose" to "the method of the derived class can use the base class to reference the derived class, the following conditions must be met: ● The derived class method and the base class method have the same signature and return type. ● the base class method uses virtual annotation. ● The derived class method uses override to mark other important virtual and override modifiers. information is as follows ● the overwriting and overwriting methods must have the same accessibility, in other words, the overwriting method cannot be private, but the overwriting method is public ● it cannot override static or non-virtual methods. ● The inherited inheritance can override the override method eg: 4. the inherited inheritance eg: SecondDerived class contains a new print method. When MyBaseClass mybc = (MyBaseClass) derived is executed, the method call only passes a level above, because the print method in the SecondDerived class is new, the output result is: if you change the new value of the print method in the SecondDerived class to override, the result is: 5. if you want the derived class to use a specified base class constructor instead of a non-parameter constructor, you must specify it in the constructor initialization statement and use the base keyword, if you want to call another constructor in the same class, you can use the this keyword, as shown in figure 6. the accessibility of a class has only two modifiers: internal and public. (Other modifiers make the class inaccessible) a class marked as public can be accessed by code in any assembly in the system, the class marked as internal can only be seen by the class in its own assembly. this is the default access level. 7. member access modifier 8. abstract member abstract members are function members designed to be overwritten. ● it is marked with modifiers. ● it does not implement code blocks. The code blocks of abstract members are represented by semicolons. ● abstract members can only be declared in abstract classes. ● although abstract members must be overwritten with corresponding members in the derived classes, virtual modifiers cannot be appended to abstract modifiers. ● virtual member. The override modifier must be specified for the implementation of abstract members in the derived class. compare virtual and abstract Members 9. abstract classes are designed to be inherited. abstract classes can only be used as the base classes of other classes. ● abstract classes are declared using abstract modifiers. abstract classes can contain abstract members or ordinary non-abstract members. ● eg: data members cannot be declared as abstract 10. sealing class ● the sealing class can only be used as an independent class and cannot be used as a base class ● the sealing class uses the sealed modifier to mark 11. ● the static class itself must be marked as static ● the static class can have a static constructor, but there is no instance constructor and instances of this class cannot be created ● eg: 12. when a class is both sealed (that is, it cannot be inherited) and cannot be modified, you can use the extension method to add a method to the class. ● The class that declares the extension method must be declared as static ● The extension method itself must be declared as static ● The extension method must contain the keyword "this" as its first parameter type, and follow the name of the class to which it extends ● structure of the Extension Method eg: 1. A number does not have a Boolean value. 2. superficial comparison and deep comparison ① superficial comparison: if the references are equal, that is, if they point to the same objects in the memory, the equality comparison is true; otherwise, false is returned, even if the two separated objects in the memory are completely equal in all other aspects, it is also false ② deep comparison: if the two strings have the same length and the same case sensitive content, then the equality comparison returns true, even if they occupy different memory areas. 3. logical operators 4. ① implicit conversion Syntax: eg: ② explicit conversion Syntax: replace implicit in the implicit conversion syntax with expliciteg: 5. operator Overloading is similar to user-defined implicit and explicit conversions. only the following operators can be overloaded. eg: overload negative number, subtraction and addition 6. typeof Operator

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.