-
June 5th, 2013, 12:19 PM
#1
What is the difference to instantiate an integer using new and without new?
For example,
Code:
int i = 0;
int i = new int(0);
Is there any difference? Thanks.
-
June 5th, 2013, 02:11 PM
#2
Re: What is the difference to instantiate an integer using new and without new?
What do you think the differences are, if any? Btw, a basic C# book will explain this too you better than posting to a forum.
-
June 5th, 2013, 02:42 PM
#3
Re: What is the difference to instantiate an integer using new and without new?
There is absolutely no difference.
-
June 5th, 2013, 03:09 PM
#4
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.
-
June 5th, 2013, 03:28 PM
#5
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.
Why not use the built-in profiler to see what is really happening?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|