Declare and use read write properties in C# Part 3 – Create an instance of the Person class and set values on the object
1 min read

Declare and use read write properties in C# Part 3 – Create an instance of the Person class and set values on the object

So finally we’ll create a new instance of the class inside our Main of the TestPerson class. Then we’ll set some values on the object and then increment the property.

        var detective1 = new Person();

        detective1.Name = "Sherlock";
        detective1.Age = 37;
        Console.WriteLine($"Detectives age is {detective1.Age} and he's name is {detective1.Name}");

        detective1.Age += 1;
        Console.WriteLine($"And now he's a year older! {detective1.Age}");

Time to run the app!

Great work Sherlock!

Leave a Reply