C # Learning Diary---Reference type of data type (preface)

Source: Internet
Author: User
Before we learned the simple data type in C #----value type, followed by another data type in C #----reference type, the term "reference" here means that a variable of that type does not directly store the value it contains, but instead points to the value he wants to store, which means that the reference type stores the address of the variable. There are 4 types of references in C #:

    • Class

    • Represent

    • Array

    • Interface

Here I first outline the respective meaning and definition of the way, I will be specific to write examples in detail.

Class

A class is an object-oriented basic unit, a data structure that contains data members, function members, and nested types. The data members of a class have constants, fields, and events, function members include methods, properties, index indicators, operators, constructors, destructors, and classes and structs (structs) also contain their own members, but the main difference between them is that the class is a reference type, and the struct is a value type. The class supports inheritance mechanisms by inheriting derived classes to extend the data members and function methods of the base class to achieve the purpose of code reuse and design reuse. (The inheritance of the class, the derivation will be put in detail later, the next will write the definition of the Class), when you define a class, you define a data type blueprint. This does not actually define any data, (because it is an address) but it defines what the name of the class means, that is, what the object of the class is made of and what operations are performed on the object. An object is an instance of a class. The methods and variables that make up the class become members of the class. If we define a variable for a class, we call it an instance of the class (it can also be called an object, in short, it will be changed later). Again, the 2 commonly used class object classes and String classes in C # are also described later.

Represent

The Representative in C # (also called a delegate, Delegate), which is similar to a pointer in C + +, but the pointer is unsafe in C + +, it is possible that an accidental deletion could cause the entire program to crash, while Delegate is safe in C #. Delegate refers to a method that derives from the System.Delegate class, when a Delegate is defined as an extension to the system.delegare. The specifics of the usage are detailed later.

Array

In batch processing of data, we will use arrays, as in C + +, the array is a set of identical types of ordered data, used to store the data collection, according to the array name, the type of data elements and the number of dimensions to describe. The System.Array provided in C # is the base class for all array types. One of the specified elements in the array is accessed through an index. All arrays are made up of contiguous 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 contracts that should be followed when all classes inherit an interface. The interface defines the "what" part of the syntax contract, and the derived class defines the "How to" section of the syntax contract. An interface defines properties, methods, and events, which are members of an interface. The interface contains only the declarations of the members. The definition of a member is the responsibility of the derived class. The interface provides the standard structure that a derived class should follow. Abstract classes are somewhat similar to interfaces, but most of them are only used when only a few methods are declared by the base class by a derived class. (That is, the interface provides only the declaration of a method, which is determined by inheriting his subclass.) For example, I give 5 people 100 yuan per person, they take this 100 yuan specifically what is not my business, I only provide money) interface uses the interface keyword declaration, which is similar to a class declaration. The interface declaration is public by default. Multiple inheritance can be achieved through an interface. (Detail later)

These are the contents of the reference type (preface) of the C # Learning Diary---Data types, and more about topic.alibabacloud.com (www.php.cn)!

  • 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.