1
Answer

Why difference in behaviour of 'new' outside and inside unsafe block?

vikrampschauhan

vikrampschauhan

19y
1.7k
1
In C#, for class MyClass, on doing: MyClass myClass=new MyClass(); myClass will hold an address, that was returned by new. But if we have an unsafe block of code, unsafe { MyClass myClass1=new MyClass(); } myClass1 is created as an object on the stack. new merely calls the constructor of MyClass. Am I correct? I believe that class objects created in the unsafe block can only be placed on the stack. Am I correct? (I inferred the above from a code-snippet behaviour, I experienced) Thanks Vikram
Answers (1)
Next Recommended Forum