What is the 'new' keyword used for in C#?

Experience Level: Junior
Tags: C#

Answer

In C# the new keyword is used to create a new instance of a class. We are also saying the new keyword is used to construct an object.

To construct an object, put the new keyword followed by a class name, open and close bracket and a semicolon to your source code. In the following example, the code new Car(); does the magic.

Example
using Cars;

namespace MyApp {
  class Program {
    static void Main() {
      var myCar = new Car();
    }
  }
}

Comments

No Comments Yet.
Be the first to tell us what you think.
C# for beginners
C# for beginners

Are you learning C# ? Try our test we designed to help you progress faster.

Test yourself