Define a class in C# and create an instance of the class Part 2 – Create a new class

Write click on the solution and create a new class and name the class file


Set the access modifier to public.

    public class Person


Create an auto-implemented read only property.

public string Name { get; }

Next add a constructor that takes one argument.

        public Person(string name)
            Name = name;

Now in the next post we’ll instantiate two instances of our Person class.

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: