6.3 Creating an object with the new operatorLike Java, there is only one way [4] to create a new object in C# “ by using the new keyword.
Like JavaCreating 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 ' o ' is an alias for the System.Object class in C#): new object(); The expression returns an object reference to the new object created on the heap, which you should assign to a variable of an appropriate reference type. The following works fine: object o = new object(); Unlike JavaIn C#, the keyword new can also be used to create a method which hides a method of the same signature in a superclass. So, don't be surprised to see a method being declared like ' new public void DoSomething(); ' in C#. This is called ' name hiding', or in this case 'method hiding'. |