C # differences between classes and interfaces, value types, and reference types

Source: Internet
Author: User

1. Classes and interfaces

In C #, interfaces are responsible for defining functions. In projects, interfaces are used to define classes, while classes are specific functions of negative tables.

A class can inherit a base class, that is, the parent class, but can implement multiple interfaces (the interface actually implements Multi-inheritance ).

The class also has the definition of abstract classes. abstract classes use abstract declarations. abstract classes cannot be listed in real form. abstract classes can have abstract methods and attributes, you can also have specific methods and attributes. That is to say, abstract classes can have abstract methods or specific methods, but classes with abstract methods must be abstract classes.

An interface is only a function definition and a behavior specification. An interface can contain methods and attributes, but these attributes are only defined without an implementation body.

2. Value Type and reference type

The difference between the value type and the reference type is that the variable of the value type directly stores actual data, while the variable of the reference type stores the data address. A Value Type Variable directly stores the value of the variable in the stack, allowing you to quickly access the actual data from the stack. Therefore, the value type indicates the actual data, the reference type variable stores the actual data address in the stack, while the actual data is saved in the heap. Indicates the pointer and reference to data stored in the memory heap (including classes, interfaces, arrays and strings). Therefore, the most basic difference between the value type and the reference type is the memory storage mode.

 

Value Type reference type variable storage content actual value Reference Memory Unit stack heap transfer parameter actual value reference (object)

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.