Introduction to Objects and Classes
In this section, you will get familiar with the basic building blocks of object-oriented programming: Objects and Classes.
We'll cover the following
Definitions
A class can be thought of as a user-defined blueprint or prototype used for creating objects. In other words, a class specifies what properties an object should have and how it should behave.
We referred to classes as the blueprints for creating objects. When looking at it from an object’s perspective we can say that objects are the run time instances of classes. This may not make much sense right now, but we will look into it practically by creating our own objects soon.
From the above discussion we can infer that:
An object is an instance of a class.
In C#, we have several different data types like int,
char,
bool
etc.
We can use any of these types in the program, but they provide very limited features to the developers. Well, object-oriented programming wouldn’t make sense if we couldn’t define our own data types. This is where classes come into play.
Classes are used to create user-defined data types. The predefined string
data type in C# is also a class. We can use predefined data types to create our own classes. The cool part is that our classes can contain multiple variables and methods to manipulate these variables which would be available to us whenever a class object is created.
Get hands-on with 1400+ tech skills courses.