Blog

Learn OOPs using C#

Posted 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.

er.png

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

er1.png

Step 3 : Now add the following code in Flower class

er3.jpg

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.

er2.jpg

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.)

COMMENT USING
PREMIUM SPONSORS
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.
Employers - Post Free Jobs
SPONSORED BY
  • MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.