C # Stack Tutorial

Source: Internet
Author: User

1: Stacks are stacks, because heaps and stacks are too awkward to say, like tongue twisters, so sometimes the stack is abbreviated as a stack . Heap and Stack, you see how comfortable this is. But whenever the stack is not equal to heaps and stacks, it must be said that heaps and stacks or heaps and stacks .   

2: Value type variables and reference type variables are stored inside the stack. Whereas a value type variable holds the value of a value type instance, a reference type variable holds a reference to the instance of the reference type. A reference to an object is a pointer to an address in the heap that is saved in the heap, which is the object instance

3: usually an object itself contains an instance of a value type and an object, which distinguishes between the concepts of fields and variables. in general, it can be said that the declaration in a class is a field, which is declared in a method, is a variable. The field has an access modifier (public/private/protected/internal), and the variable does not.

4: The difference between a variable and a field , the field and the variable are similar, but in fact there is a big difference. The variable is always stored inside the stack, and the field follows the instance of the class.

5: The stack is a table that satisfies the last-in-first-out; the heap is a tree that satisfies the parent node's total not equal to (or not less than) the child nodes. not An object instance is a heap (a member of an object is a node), but all object instances are a heap (an object is just a node in the heap).

Value type:

Int

Float

Char

Double

Structure

............

Reference type:

Class

Interface

Array

String

1: Data of value type is stored in the stack of memory and can be accessed quickly from the stack, so the value type represents the actual data.

2: A reference type represents a pointer or reference to data stored in the memory heap.

3: When data is released, value type data is automatically freed, and reference type data needs to be reclaimed by the garbage collector.

4: The default value of the value type is:0, the default value of the reference type is:null

for a class of value type, an instance of the class is stored in a variable, that is, an instance of the class follows the variable on the stack.   

for classes of reference types, an instance of the class is stored on the managed heap.   

C # Stack Tutorial

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.