Create a Model Class

Learn how to create a model class using Visual Studio 2019.

Creating a model class

To create a model class in the solutions explorer, right-click on Models folder > Add > New Item.

Select “Class” and type the model classes’ name. Make sure the name of the model class is singular. We are naming it Person.cs.

A class will be generated. Here, properties are declared along with their getter and setter methods.

Populating a model class

Inside the class that you have created, type “prop” and press the Tab key twice and it will automatically generate a property with a getter and setter.

public int MyProperty { get; set; }

Data type and property names can be easily updated. Datatype will be selected by default. Type the required data type. Afterward, press Tab twice again to select the property name. Now, type in the property name.

Get hands-on with 1200+ tech skills courses.