[Learn More] C # basic knowledge

Source: Internet
Author: User

Padding-left: 3px; padding-Right: 5px; "class =" noprint ">

1. Object-oriented ideas mainly include: inherited multi-state Encapsulation

● Encapsulation: the data and data-based operations are encapsulated with abstract data types, and the data is protected within the abstract data type.

● Inheritance: subclass has all data and operations of the parent class.

● Polymorphism: OneProgramIf different methods with the same name coexist in.

There are two forms of polymorphism-overloading and rewriting.

 

2. What is packing and unpacking?

The boxing and unboxing mechanisms enable conversion between any value type, reference type, and object type in the C # type system. This conversion is called a binding connection. Simply put, with the concepts of packing and unpacking, values of any type can be regarded as objects. 1. Packing and conversion

Meaning: implicitly convert a value type to an object type, or convert the value type to an interface type applied to this value type, and pack a value type value, creates an object instance and copies the value to the object.

For example: int I = 10; object OBJ = I; you can also use an explicit method for packing: Object OBJ = (object) I;

2. binning and conversion

In contrast to packing, unpacking refers to explicitly converting an object type into a value type, or explicitly converting an interface type into a value type that executes this interface.

The process is divided into two steps:

First, check this object instance to see if it is a boxed value of the given value type.

Then, copy the Instance value to the value type variable. For example:

Int I = 10;

Object OBJ = I;

Int J = (INT) OBJ;

 

3. overload and override

Overload is the method inherited from the pointer pair, and its processing method is re-designed to overwrite the original Processing Method in the future.

Override is added before the method to be overwritten by the derived class, and virtual is added before the method of the base class with the same name. In this way, polymorphism can be achieved. Polymorphism refers to the coexistence of different methods with the same name in a program. There are two forms of polymorphism-overloading and rewriting.

 

4. Value Type and reference type
● Variable of the value type itself contains their data, while variable of the reference type contains a reference or handle pointing to the memory block containing the data.

● Value type variables are stored in the stack. Each program has its own stack during execution, and other programs cannot be accessed.

● The reference type is stored in the heap. The address of the reference value for storing the actual data of the reference type.

● There are four reference types in C #.

● (Class, representative, array, interface)

 

5. Understand Delegation

Proxy is a new type in C #. A proxy is required to pass methods as parameters to other methods.

The method uses parameters to obtain the data that is passed by the outside world and perform some operations on the data.

C # implement it through the proxy mechanism and pass a method to another method through parameters.

Proxy Step 4:

A. Generate a custom proxy class: Delegate int mydelegate ();

B. Use the new operator to instantiate the proxy class:

Mydelegate d = new mydelegate (myclass. mymethod );

C. Call the method through the Instance Object: int ret = D ();

D. In a program, the Instance Object of the application proxy calls the method it points to, just like calling a method. Delegate int D (int I );

 

6. interfaces and classes in C #

What is a class? Classes can be understood as a set of functions. classes can also be seen as a set of functions or methods. The concept of interfaces: What is an interface? Interfaces can be understood as Class rules, class constraints, and even project constraints. template defines the methods that must be implemented by the object, so that these methods can be referenced as interface instances. The interface cannot be instantiated. The interface is responsible for defining functions. The project uses interfaces to define the concepts of classes, Operation classes, and abstract classes! The class is responsible for the specific implementation of the function! There is also an abstract class definition in the class. The difference between the abstract class and the interface is that the abstract class is an incomplete class, which contains abstract methods and attributes, you can also have specific methods and attributes that require further specialization. But the interface is a behavior specification, and everything in it is abstract! A class can only inherit one base class, that is, the parent class, but multiple interfaces can be implemented.

 

7. Classes required for reading and writing databases in. net

Connection dataadapter dataset command datareader

 

8. Understand the garbage collection mechanism in. net

If the memory is not enough, the garbage collector takes all the objects as invalid objects (recycled objects), and then takes the global variables, static, and local variables in the active state, and put the object pointed to by the current CG pointer into a table. then

The system searches for objects in the new list and adds them to the list. Other objects not included in the list will be recycled.

For unmanaged objects, remember to release resources.

 

9.. Net Error Handling Mechanism

Error handling sequence: Finally first, catch second, and finally exit tryCode.. Cancel this operation. returns exception information in catch. of course, you can also customize your own error handling mechanism... if your exception handling contains finally blocks. then this finally will always be executed regardless of whether an exception occurs...

 

Using and new in 10. C #

Using is used to create an alias for a namespace or reference other namespaces in the system.

New is used to create instances or override methods.

 

11. Differences between classes and structures

1. Value Type and reference type

● Structure is value type: value type is allocated on the stack.

● The class is a reference type: the reference type is allocated to the address on the stack.

2. Inheritance

● Structure: it cannot be inherited from another structure or class. Although there is no clear sealed declaration, the structure can be implicit sealed.

● Class: fully scalable. Unless sealed is explicitly declared, the class can inherit from other classes and interfaces and inherit from itself.

Note: although the structure cannot be inherited, the structure can inherit interfaces. methods are the same as class inheritance interfaces.

3. Differences in the internal structure:

Structure:

● No default constructor exists. You can add constructor.

● No destructor

● No abstract and sealed (because it cannot be inherited)

● There cannot be a protected Modifier

● New Initialization is not required.

● It is incorrect to initialize the instance field in the structure.

Class:

● Default constructor available

● Destructor

● Abstract and sealed can be used.

● There is a protected Modifier

● New must be used for initialization.

 

12. CLR

Common Language Runtime (CLR) provides a reliable and complete multi-language runtime environment. CLR is a software engine used to load applications, check errors, perform security license authentication, execute, and clear memory. It is a type of pure dynamic runtime. Its main component is virtual execution enging, which can break the language and platform restrictions.

 

13. Advantages of C #

 

1. the pointer in C # has disappeared. Restrictions on the use of the original pointer are allowed.

2. Based on the. NET platform, it inherits the features of Automatic Memory Management and garbage collection.

3. C # has built-in support to convert any component into a web service. Any application running on any platform can use this service over the Internet.

4. Object-oriented

14. Three Principles of Object-Oriented Programming

● Inheritance: each class supports a single inheritance, but the class can implement multiple interfaces. All classes are inherited from a common base class.

● Encapsulation and visibility: You can determine whether class members are visible. Besides the internal access modifier of C #, the visibility mechanisms of the two are very similar.

● Polymorphism: Java and C # both support some forms of polymorphism, And the implementation methods are very similar.

 

15. C #5 types of accessibility

● Public: Members can access any code.

● Protected: A member can only be accessed from a derived class.

● Internal: members can only access from within the same assembly.

● Protected internal: A member can only be accessed from a derived class in the same assembly.

● PRIVATE: members can only access the current class.

 

16. C # compile the code into an intermediate language before execution. The main features of the intermediate language are as follows:

● Object-oriented and user interfaces

● The huge difference between the value type and the reference type

● Strong data types

● Use exceptions to handle errors

● Attribute)

 

17. C # reference type

(Class, representative, array, interface)

18. Three possible relationships between objects

● Aggregation: An (complex) object is composed of several (simple) other objects, called aggregation.

● Association: static connections between objects (that is, links embodied by object attributes) are called associations.

● Inheritance.

 

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.