Introduction to Objects and Classes in C# - Programmerís Classes and Objects (Page 4 of 9 )
A C# Class is considered to be the primary building block of the language. What I mean by the primary building block is that every time you work with C# you will create classes to form a program. We use classes as a template to put the properties and functionalities or behaviors in one building block for a group of objects and after that we use the template to create the objects we need.
For example, we need to have persons objects in our program so the first thing to do here is to create a class called Person that contains all the functionalities or behaviors and properties of any person and after that we will use that class (or template) to create as many objects as we need. Creating an object of a specific class type is called "an instance of the class". Don't worry if you didn't grasp it 100% and don't worry if you don't know what the class and object's properties and functionalities or behaviors are because we are still in the beginning. Until now I havenít provided any code examples. So let's take a brief of what is a class and what is an object:
The class: A building block that contains the properties and functionalities that describe some group of objects. We can create a class Person that contains:
The properties of any normal person on the earth like: hair color, age, height, weight, eye color.
The functionalities or behaviors of any normal person on the earth like: drink water, eat, go to the work.
Later we will see how we can implement the functionalities or behaviors and properties.
There are 2 kinds of classes: The built-it classes that come with the .NET Framework, called Framework Class Library, and the programmer defined-classes which we create ourselves.
The class contains data (in the form of variables and properties) and behaviors (in the form of methods to process these data). We will understand this concept later on in the article.
When we declare a variable in a class we call it member variables or instance variables. The name instance come from the fact that when we create an object we instantiate a class to create that object. So instance of a class means an object of that class and instance variable means variable that exists in that class.
The object: It's an object of some classification (or class, or type) and when you create the object you can specify the properties of that object. What I mean here is: I, as an object, can have different properties (hair color, age, height, weight) than you as another object. For example, I have brown eyes and you have green eyes. When I create 2 objects I will specify a brown color for my object's eye color property and I will specify a green color for your object's eye color property.
So to complete my introduction to classes we must discuss properties and variables.