What is the difference to instantiate an integer using new and without new?

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: What is the difference to instantiate an integer using new and without new?

Originally Posted by David Anton

There is absolutely no difference.

This is quoted from MSDN,
new operator Used to create objects on the heap and invoke constructors.
Value-type objects such as structs are created on the stack, while reference-type objects such as classes are created on the heap.

Since integer is value type so it must be created on the stack. But on the other hand, new operator will create object on the heap if we are using int i = new int(0). It looks like conflicting. Correct me if I am wrong. Thanks.

Re: What is the difference to instantiate an integer using new and without new?

Originally Posted by LarryChen

This is quoted from MSDN,
new operator Used to create objects on the heap and invoke constructors.
Value-type objects such as structs are created on the stack, while reference-type objects such as classes are created on the heap.

Since integer is value type so it must be created on the stack. But on the other hand, new operator will create object on the heap if we are using int i = new int(0). It looks like conflicting. Correct me if I am wrong. Thanks.