C # Object-oriented technology

Source: Internet
Author: User

I. Basic knowledge

Class:

The benefits of encapsulation: Good encapsulation reduces coupling, the implementation within the class can be freely modified, and the class has a clear external interface.

Class is a structure in C # that simulates real-life objects in a program;

Member variables represent the characteristics of an object;

Method represents an action that an object can perform;

If a constructor is not defined in the class, the runtime provides a default constructor;

Destructors cannot be overloaded, and each class can have only one destructor;

Methods can be overloaded according to different number of parameters or different data type parameters, and cannot be overloaded according to the return value;

Namespaces are used to define the scope to which a class belongs, similar to a package in Java.


Characteristics:

Inheritance is the process of acquiring the function of an existing class;

The base class on which the new class is created is called the base class or parent class, and the new class is referred to as a derived class or subclass;

The base keyword is used to access base class members from derived classes;

The override keyword is used to modify a method, property, or indexer. The new access modifier is used to explicitly hide members that inherit from the base class;

An abstract class is a class of at least one abstract member (a method that has not yet been implemented), and an abstract class cannot be implemented;

The overriding method is to modify the implementation of the method in the base class, and the virtual keyword is used to modify the declaration of the method;

The display interface implementation is used to determine which interface the member function implements in the case of ambiguous names.


Senior:

Errors and exceptions

C # uses a technique, exception handling, to provide a mechanism for dealing with error situations, which provides a custom approach to each error situation, and separates the code that identifies the error from the code that handles it incorrectly;

Data type conversions

How to convert data types implicitly or explicitly;

Pretreatment

When compiling the code, the first preprocessing, so that the code can be replaced by the text, you can also generate different programs to meet the needs of different situations;

Unsafe code

C # Typically traps the details of memory access, simplifying the processing of the code, but there are some situations that require direct access to memory. C # allows for direct access to memory by declaring tagged code as unsafe code.


Noun Explanation:

Operator overloading

Can add, subtract, multiply, divide, and so on the instance of the class;

Index character

It allows syntax to be handled by arrays and simplifies the use of classes that contain many objects;

Commissioned

C # allows the code to refer to a method without specifying what method to reference, which can be specified at run time, which is similar to the function pointers in C + +, but they are type-safe and object-oriented;

Event

When programming, it is often necessary to tell some code what to learn to perform an action, such as when the user clicked the mouse button. C # uses events to provide for this occasion; built-in support.

this keyword

This is a reserved word that is used only in constructors and method members

A reference to the object being constructed is represented in the class's constructor, and a reference to the object that called the method appears in the method of the class, a reference to the structure being constructed is represented in the structure's constructor, and a reference to the result of the call to the method appears in the structure's method.

This reserved word cannot be used in the implementation of a static member because the object or struct is not instantiated

In a C # system, this is actually a constant, so an operation such as this++ cannot be used

This reserved word is typically used to qualify a hidden member with the same name, to make the object itself a parameter, to declare an index accessor, to determine whether an object passed in as a parameter is itself

Two. Course of study

In the process of learning C #, it is: very sad! Although the feeling of learning the relevant knowledge language, can still feel very difficult to understand. First draw a picture, describe the course.

In the learning time still feel this language is a little different, their ability is not enough, still need to work hard!



Three. Compare growth

1. What are the differences between classes and structures?

Class:

A class is a reference type that is allocated on a heap, and an instance of a class is assigned a value that simply duplicates the reference and points to the memory allocated by the same actual object.

Class has constructs and destructors

Classes can inherit and be inherited

Structure:

A struct is a value type that is allocated on the stack (although the stack's access speed is faster compared to the heap, but the stack has limited resources), the assignment of the structure assigns a new object.

Structs do not have constructors, but can be added. struct does not have a destructor

Structs can not inherit from another struct or be inherited, but can inherit from the interface as a class


2. What are the problems associated with multiple inheritance of interfaces?

Interfaces in C # differ from classes in that they can use multiple inheritance, that is, a subinterface can have more than one parent interface. However, if two parent members have a member with the same name, there is a two ambiguity (which is one of the reasons why classes in C # are canceling multiple inheritance), and it is best to use explicit declarations when implementing


3. What are the differences between abstract classes and interfaces?

Abstract classes can contain function definitions and implementations, and interfaces (interface) may contain only function definitions

Abstract classes are concepts that are abstracted from a series of related objects, and thus reflect the internal commonality of things; an interface is a functional contract defined to satisfy an external invocation, so it reflects the external nature of the thing.

Analyzing objects, refining internal commonalities to form abstract classes to represent the nature of objects, i.e. "what"

The interface is preferred when the external invocation or function needs to be expanded


4. What is reflection?

Reflection, Reflection, through which we can get a variety of information at run time, such as assemblies, modules, types, fields, properties, methods, and events

You can also perform actions on a type after it has been dynamically instantiated

In a nutshell, a string can do whatever it wants in the runtime, which is actually a. NETFramework built-in universal factory

Generally used for the implementation of plug-in framework programs and design patterns, of course, reflection is a means to give full play to its energy to do anything you want to do (it seems like you've seen a man call a function not described in the official class library with reflection. )


5. What is a delegate, a delegation chain?

A delegate (delegate) is a reference type that we treat as a class to look at instead of a method, but a delegate is a reference to a method or a list of methods, and invoking a delegate instance is like invoking a pointer in C + +, and he encapsulates a reference to the development method. Or the delegate is the function of the bridge, the delegate object after the instance will pass the given parameter to the method that he callback, and execute the method.

Entrust Chain we know that the delegate is the encapsulation of the method, and that the delegate can encapsulate many methods to form a chain of delegates, in fact, the delegate is like a container, he encapsulates a number of methods we want to implement, when invoking the delegate object (equivalent to a pointer in C + +), it will sequentially execute all the methods it encapsulates. If there is a return value, the return value of the last executed method is often returned, and the formation of the delegation chain can be performed with "+ =" or "-=" for a two-dollar operation on different delegate instances.











C # Object-oriented technology

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.