-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
The C# Workshop
By :
A class is like a blueprint that describes a concept. An object, on the other hand, is the result you get after the application of this blueprint. For example, weather can be a class, and 25 degrees and cloudless could refer to an object of this class. Similarly, you can have a class named Dog, while a four-year-old Spaniel can represent an object of the Dog class.
Declaring a class in C# is simple. It starts with the class keyword, followed by the class name and a pair of curly braces. To define a class named Dog, you can write the following code:
class Dog
{
}
Right now, this class is just an empty skeleton. However, it can still be used to create objects by using the new keyword, as follows:
Dog dog = new Dog();
This creates an object named dog. Currently, the object is an empty shell, as it lacks properties. You will see in an upcoming section how to define properties for classes, but first, you will explore constructors.