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)