C # differences between the value type declaration method int I; int j; and int I, j;

Source: Internet
Author: User

In C #, two int-type variables, I and j, are declared in two ways:

Static void Main (string [] args) {int I; int j ;}
Static void Main (string [] args) {int I, j ;}

Today, I saw the difference between C # advanced programming and recorded it.

PS: I and j are in the same scope.

The int type belongs to the value type, while the value type is stored in the stack. The stack data storage belongs to the last-in, first-out, and LIFO types.

For the first declaration method, the stack pointer will first allocate space for variable I, and then allocate space for j. When the space is reclaimed, j will be recycled before I.

For the second declaration method, the order in which the two variables enter the scope is uncertain, because the two variables are declared at the same time and also out of the scope. At this time, it is not important to delete a variable from the memory in declared order. The compiler will internally ensure that the variable is first placed in the memory and then deleted, so that the rule will not conflict with the lifetime of the variable.

 

 

-- From C # advanced programming (version 7)

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.