Class is a design, declaration or blueprint that is used for grouping object. It encapsulates variable members, functions, structure, properties, events and many more components. It is the basic constructing block of object oriented programming. You can create as many instances of your class .you can create a class by using class keyword.  

Syntax:

class Product
    {
 
    }

After creating class you can create method that contains following:

class Product
    {
        public void GetProductName()
        {
            Console.WriteLine("Samsung LS-05");
        }
    }

To use the function of class, you need to create object of this class. After creating the object of Product class, you can use its function using the object name as follow:

 Product pro = new Product();
 pro.GetProductName();

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication1
{
    class Product
    {
        public void GetProductName()
        {
            Console.WriteLine("Product Name: Samsung LS-05");
        }
        public void GetProductCode()
        {
            Console.WriteLine("Product Code: SAML-05-");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Product pro = new Product();
            pro.GetProductName();
            pro.GetProductCode();
            Console.ReadLine();
        }
 
    }
}

 

 

Output:


What is class in C#


Thanks

comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like