- Considerations for using interfaces: Members in the
- interface cannot add access modifiers
- members in the interface cannot have any implementations
- implementing an interface's subclasses must implement all members of the interface
- a class You can inherit a class and implement multiple interfaces at the same time, if a subclass inherits the parent class A and implements the interface IA, then syntactically a must be written in front of the IA because the class is single-inheritance, and the interface can implement the
- An explicit implementation interface and an implicit implementation of the interface need to be aware of the problem (we are usually implicitly implemented) the
- Up-transition
- Single-duty principle (avoid defining a bulky interface because it creates "interface pollution" and only defines the associated set of members to an interface)
- interface differs from abstract class:
-
- Same point:
- Interfaces and abstract classes are not instantiated
- Different points:
- Abstract base classes can define fields, properties, method implementations. Interfaces can only define properties, indexers, events, and methods
- An abstract class is an incomplete class that needs further refinement, while an interface is a code of conduct. Microsoft's custom interface is always the dog band able Field, proving that it is stating the "I can do ..."
- Interfaces can be implemented in multiple, abstract classes can only be inherited by a single
- Abstract classes are more defined in a series of tightly related classes, while interfaces are mostly loosely linked classes that implement a function
- Abstract classes are concepts that are abstracted from a series of related objects, thus reflecting the internal commonality of things; a functional contract defined by an interface to satisfy an external invocation, thus reflecting the external nature of the thing
- Interface basically does not have any specific characteristics of inheritance, it only promises to be able to invoke the method
- Interfaces can be used to support callbacks, and inheritance does not have this feature
- The concrete method implemented by the abstract class defaults to virtual, but the interface method in the class that implements the interface defaults to non-virtual, and of course you can declare it as virtual
- If an abstract class implements an interface, it is possible to map a method in an interface to an abstract class as an abstract method without having to implement a method in a subclass of an abstract class that implements an interface
3. Type conversion
4. Static members
-
- Load time (when static members are loaded?) )
- Loaded when the static member is first called
- Application scenario (when static members are used)
- Data that is shared within the entire program is defined as static. It is usually used as a tool class. Like Dbsqlhelper.
- The difference between a normal class and a static class
- Static classes need to be static, and static classes cannot be instantiated
- Static can only contain static members
- You can call a static member directly in an instance method, but you cannot call an instance method directly in a static method
- Static and static variables always use the same piece of memory after they are created, and methods that use instances create multiple memory spaces
- A shaking constructor cannot have parameters, nor can it be associated with an access modifier (the default is private)
5. Inheritance of static classes
-
- From the angle of the subclass: static classes cannot be inherited by any class
- From the angle of the parent class: Static classes can inherit only the object class and cannot inherit other classes
6. Access modifiers for classes and members
-
- The default access modifier for the class is internal
- The default access modifier for a member of a class is private
- There are only two types of access modifiers for a class: Public,internal (Default)
- The access modifiers for members of the class are: Public,protected,private (default)
7. Structure
-
- Essence is a value type
- Selection of value types and reference types
- Value types: Primarily used to encapsulate a set of data and provide a simple way to handle the data
- Reference type:
- Primarily used to encapsulate data and behavior
- Using object-oriented features
- Use structure when there are more members in the type (in the heap)
- The role of the new keyword
- After creating an object with the New keyword, all member variables already exist and have default values (value types)
- If you do not use the new keyword, you need the programmer to manually assign all of the used member variables before calling the method properties in the struct object
- The struct is not new and can be used, but must be assigned to the struct member used
8. Differences in class and structure
-
- A struct is a value type that is allocated on a stack of memory, whereas a class is a reference type and is allocated on the heap of memory.
- Structs cannot be inherited because structs are value types and implicitly inherit from System.ValueType
- A struct is a value-passed (Assignment pass), and a class is a reference to a passed
9. Restrictions on access levels
-
- The access level of a subclass cannot be higher than the parent class
- The access level of the method parameter >= the access level of the method (for example, when the parameter of a method passes an object of a class, the class object is accessed at a higher level than the current method's access level)
10. Destructors
11. String
-
- Property: Length
- Static methods
- Common:
- (last) IndexOf: used to find a character or string, subscript in a particular string object
- SubString Intercept
- Split () splits the string based on a specific character and returns an array of the segmented strings, which can be read with foreach
- Join static method
- Format () static method
- Replace (), replacing to receive, produces a new string
- Replace (). Replace () chained programming
- Trim () go to the end of the space
12. The difference between the "= =" operator good "Equals ()" Method
-
- "= =" when comparing:
- If the comparison is a value type, compare the values of two objects
- If you are comparing reference types, compare the reference addresses of two objects (compare heap addresses)
- "Equals ()" when compared:
- This method is a virtual method in the object class, the default is to use the "= =" and to compare, is a "= =" in a package, but, most of Microsoft's classes and user-defined classes, have overridden the virtual method, That is, both Microsoft and the user have defined equality comparison rules for each subclass of the object that they write for themselves.
Note: There is a special case, because string is a reference type, so it is logically said string. The Equals ("...") method compares the address, where the value of the string is compared
13. The constant character of the string:
When the string is created in memory and the programmer creates a string object of the same value again, the CLR optimizes to assign a reference to the first string directly to the second variable, that is, the front and back two strings are saved with the same string object applied
14.StringBuilder objects
when a String is in operation (such as assignment, stitching, and so on) a new instance is generated, and StringBuilder does not . So it's best to use StringBuilder when you have a large number of string concatenation or frequent manipulation of a string, and do not use string. If you want to manipulate a growing string, try not to use the string class instead of the StringBuilder class.
Two classes work differently: The String class is a traditional way to modify a string, and it does work to add a string to another string. Yes, but under the. NET Framework, the operation is not. Because the system first writes two strings to memory, then deletes the original string object, creates a string object, and reads the data in memory to the object. This carefree matter, it took a lot of time. This is not the case with the StringBuilder class under the System.Text namespace, which provides a Append method that can be used to modify the string in place of an existing object , simply and directly. Of course, the difference in efficiency is not generally noticeable, but if you want to do a lot of adding to a string, the time and the string class of the StringBuilder class are simply not a number of levels.
dotnet Knowledge Point Summary three (note integration)