O'Reilly logo

From Java to C#: A Developer's Guide by Heng Ngee Mok

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

6.3. Creating an object with the new operator

Like Java, there is only one way [4] to create a new object in C# – by using the new keyword.

[4] There are two ways to create a new object in C++. Car c(); (creates a Car object on the stack), and Car *c = new Car(); (creates a Car object on the heap). For the case of C#, you can only create an instance of an object using the new keyword. There is no way for the C# developer to control whether a new object is to be created on the heap or stack. All C# objects (reference types) are created on the heap, and all value types are created on the stack.

Like Java

Creating an object in C# is very similar to creating an object in Java. The following statement creates a new object object (object with a small ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required