new Int32() usages in c#?

.net, .net-4.0, c#, int

Solution

All structs (and int/Int32 is a struct) allow new() usage, which just means: initialise the struct to default values, I.e. zero for all fields in the struct. Most structs are immutable - and primitives certainly are. Basically, what you have written is the same as:

int k=0;

You can do lots of things with that.... But you can't change any properties of zero. Zero is zero is zero.

`new` does not always mean "allocate on the heap".

Problem

C# compiler allows me to write : ``` int k=new Int32(); ``` However , I can't assign any value to it. 2 questions 1) doesnt `new` create a Heap allocation , and if so , what about the stack<->value thing ? 2)I can't do nothing with `int k=new Int32();`. in what scenarios will I use it ?

Original source