Tech News

What is Classes and Objects in C# .NET ?

Objects are created from Classes, The Windows Form itself is a Class, and when you run your program, you are creating Objects: a Form object, a button object, a Textbox object, etc.


Class:

A Class is simply a block of code that does a particular job. You might have a class that handles all your database work, for example, or one that does error checking on Textboxes.
The idea is that you can reuse this code (Class) whenever you need it, or when you need it in other projects. It saves you from having to write the same thing over and over again.
Think of a Class as a recipe. If you had a recipe for a chicken biryani, the recipe will tell you what you need to do to make the biryani. But it’s not the biryani itself. It’s the instructions for the biryani. If you have the recipe, you can make chicken biryani whenever you need them.


Object:

An Object is the thing that the recipe makes – The Chicken biryani itself. You do all the coding in a Class (recipe), and then instruct C# to make an object (Chicken). 
But all you are really doing with Classes and Objects is trying to separate code into blocks, so that it can be reused. When the code is being used, it’s an object. But the object is created from your code (Class).

An object is an instance of a class through which we access the methods of that class. “New” keyword is used to create an object. A class that creates an object in memory will contain the information about the methods, variables and behavior of that class.


Example:



Reference:
http://www.c-sharpcorner.com/UploadFile/84c85b/object-oriented-programming-using-C-Sharp-net/ 

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x