C # Learning diary 12 --- reference type of data type (preface)

Source: Internet
Author: User

C # Learning diary 12 --- reference type of data type (preface)

 

We have learned the simple data type in C #-value type, and the other data type in C #-reference type, this type of variable does not directly store the included value, but points to the value to be stored, that is, the address of the variable stored for the reference type. There are four types of reference in C:

Class represents the array Interface

Here I will give a general introduction to their respective meanings and definitions. I will introduce them in detail later.

 

Class

Class is the basic unit of object-oriented programming. It is a data structure that contains data members, function members, and nested types. Data members of a class include constants, fields, and events. function members include methods, attributes, index indicators, operators, constructors, and destructor. Class and structure (struct) they also contain their own members, but the main difference between them is that the class is the reference type, and the structure is the value type. Class supports the Inheritance Mechanism. by inheriting a derived class, you can extend the data members and Function Methods of the base class to achieve code reuse and design reuse. (The Inheritance and derivation of classes will be detailed later, and the next article will write the definition of classes.) When you define a class, you define a blueprint for the data type. This does not actually define any data (because it is an address), but it defines what the class name means, that is, class Object composition and what operations can be performed on this object. The object is a class instance. The methods and variables that constitute the class become members of the class. If we define a variable for a class, we call it an instance of the class (or an object ). Here, the two common class Object classes and String classes in C # are also described later.

Representative

C # stands for (also called Delegate, Delegate). It is similar to the pointer in C/C ++, but the pointer is insecure in C/C ++, an accidental deletion may cause the entire program to crash, while Delegate is safe in C. Delegate references a method derived fromSystem. DelegateClass. If a Delegate is set, it is an extension of System. Delegare. The specific usage will be detailed later.

 

Array

Arrays are used for Batch Data Processing. Like C/C ++, arrays are ordered data of the same type and are used to store data sets, the description is based on the array name, Data Element type, and dimension. The System. Array provided in C # is the base class of all Array types. A specified Element in the array is accessed through an index. All arrays are composed of consecutive memory locations. The lowest address corresponds to the first element, and the highest address corresponds to the last element.

 

Interface

The interface defines the syntax contract to be followed when all classes inherit interfaces. Interface defined syntax contractWhat isSection, the derived class defines the syntax contractHow to do. The interface defines attributes, methods, and events. These are all members of the interface. The interface only contains the Declaration of Members. The definition of a member is the responsibility of a derived class. The interface provides the standard structure that the derived class should follow. Abstract classes are similar to interfaces to some extent. However, they are mostly used only when only a few methods are implemented by the Base class declaration by the derived class. (That is to say, the interface only provides method declarations. The specific method is determined by inheriting its subclass. For example, if I give 5 people 100 yuan each, it is none of my business to do what they take the 100 yuan, and I am only responsible for providing money) Interface UsageInterfaceKeyword declaration, which is similar to the declaration of the class. The interface declaration is public by default. Multiple inheritance can be implemented through interfaces. (Later)

 

 

 

 

 

The reference type is much less than the previous value type, but every one of them is much more complicated. Please comment out what is wrong or wrong. Thank you for reading. ^_^

 

 

 

 

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.