How do you understand the class and object orientation.
Class 1 Introduction
1) Why use oop? (Object-Oriented Programming) oop has three features: encapsulation, inheritance, and polymorphism.
2) method in 3 of Instantiation
Text mytext = new text () New generates an object. The object variable mytext is only a reference to the object ,... The object is saved in the heap, and the object variable exists in the stack (the address of the object inside the heap ),
Filestream FS = file. Create ("data. Indium") -- (for constructors that are not accessible, the create method returns a reference to the class instance)
Use reflection (reflection)
3) Static members,
A static member does not belong to any object. 1. It can be accessed directly by class name. 2. An instance Member must create an object reference for access.
The start of a constant is an implicit static state, and can be directly accessed by the class name.
Public const double Pi = 3.1415;
Public static int p = 0;
Conclusion: The instance field is related to an instance of the class. each instance of the class has its own copy of the Instance field, and the static field is related to the class itself, it is not related to the instance. No matter how many class instances you create, the static field has only one copy.
When to use static, when we need global data and code (the code is public ), the static keyword after C #2.0 can also be used to modify the class (when any member of the class is static)
3. namespace
Namespaces can be divided by logic. 1 enhances readability and 2 reduces class name conflicts.
2) Hierarchical namespace (namespace can also contain other namespaces)
Namespace teamx
{
Namespace business
{
Pubclic Class {}
}
}
4 components,
Component: in our own words, many components are put together with classes.. NET is also called assembly. The component is related to the physical location of the storage and has no direct relationship with the namespace.