No in both cases.
The difference is that strings are reference types, int32 is a value type - and that's im portant, because neither of these lines strictly speaking instantiates anything - they create stack based variables and assign a value to them.
When you instantiate a reference type in a method
void foo()
{
MyClass mc = new MyClass();
}
The variable
mc
is also stack based, but the instance of the MyClass that is assigned is on the heap, and can be persisted beyond the method by assigning it to an external (class level) variable, or by returning it to the caller:
MyClass MC;
void foo()
{
MyClass mc = new MyClass();
...
MC = mc;
}
MyClass foo()
{
MyClass mc = new MyClass();
...
return mc;
}
in both cases, the variable
mc
ceases to exist when the method ends, but the heap based reference persists and can be used by other methods.
Value types are different: each time you use them, a copy is made so if we did this:
int I;
void foo()
{
int i = 666;
...
I = i;
}
The value in both
I
and
i
would be the same - 666 - but they are not the same variable, so any change to one does not affect the other in any way:
int I;
void foo()
{
int i = 666;
...
I = i;
i = i / 3;
}
i
and
I
now contain different values: 222 and 666 because they are value types.
So the answer to your question is "No" - because with value types no instantiation takes
place, so there is no interning either. Generally speaking, the "literal value" of a value type is stored directly in the IL code which constructs and initializes the variable.
And strings are a special case: they intern because they are immutable, not because they are reference types - no other reference type interns!