Learn OOPs using C#

By Naveed Zaman Blogs | Learn .NET May 07, 2013
This blog is all about the OOPs concept.
Download Files: LearnClass.rar

Introduction to C# Classes

C# is totally based on OOPs. First of all, a class is a group of similar methods and variables. A class contains definition of variables, methods etc in most cases. When you create an instance of this class it is referred as an object. On this object, you use the defined methods and variables.

Step 1 : Create the new project with name of LearnClass as show below.


Step 2 : Using Project -> Add Class we add new class in our project with the name of FLOWER.


Step 3 : Now add the following code in Flower class


In this example we have created class FLOWER. In this class we declared one public variable flowercolor. Our FLOWER class defines a constructor. It takes a parameter which allows us to initialize FLOWER objects with a color. In our case we initialize it with yellow color. The Describe() method is used to show the message. It simply returns a string with the information we provided.

Step 4 : Insert the following code in Main module.


Note: Method name FLOWER and class FLOWER is same it's the constructor of a class.(we will discuss that topic in the detail later on.)