Originally posted by: Dhaval00
Anything not initialized in the CLR world points to nothing on the heap (assuming it is a reference type). Meaning, cobj from that statement is "null".
Prior to Microsoft Visual C++ 2005, an instance of a reference type could only be created using the new operator, which created the object on the garbage collected heap. However, beginning in Microsoft Visual C++ 2005, you can create an instance of a reference type using the same syntax that you would use to create an instance of a native type on the stack. So, you do not need to use gcnew) to create an object of a reference type and that when the object goes out of scope, the compiler will call the object's destructor.
The following reference types are not available for use with stack semantics:
delegate
array (Visual C++)
String
Originally posted by: Dhaval00
Well, I am not sure about the semantics in C++, but my initial reply was based on my understanding of the CLR. My guess is any other "semantic" add-ons would probably be Microsoft specific. Moreover, the IL generated after compiling that code will be identical to the IL generated in any other .NET language. Were you able to find out if any object declared using stack semantics actually goes on the stack, even though it is a reference type (if it goes on the stack, it would be a value type then... LOL)?
Nevertheless, this is useful knowledge🙂
When you create an instance of a reference type using stack semantics, the compiler does internally create the instance on the garbage collected heap (using gcnew).
Though .Net "is" Microsoft "specific" so to speak.
Originally posted by: Dhaval00
Though .Net "is" Microsoft "specific" so to speak.
The Framework is. Not the stack on which it sits - the CLR is a standard. There's .NET and then there is MONO 🙂