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

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: