Tuesday, 30 May 2017

What is class in C# ?

Classes are the user defined data types that represent the state and behaviour of an object.
Class is nothing but an encapsulation of properties and methods that are used to represent
a real-time entity.State represents the properties and behaviour is the action that objects can perform.
The state are used to describe the data the class will be holding.
The behaviour tells what are the operations that can be performed on the data.


Syntax..

Access Modifiers  class Accounts
{
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplicationclass
{
    class Box
    {
        public int length;   // Length of a box
        public int breadth;  // Breadth of a box
        public int height;   // Height of a box

        static void Main(string[] args)
        {
            Box Box1 = new Box();   // Declare Box1 of type Box
            Box Box2 = new Box();   // Declare Box2 of type Box
            int volume = 0;    // Store the volume of a box here

            // box 1 specification
            Box1.height = 5;
            Box1.length = 6;
            Box1.breadth = 7;

            // box 2 specification
            Box2.height = 10;
            Box2.length = 12;
            Box2.breadth = 13;

            // volume of box 1
            volume = Box1.height * Box1.length * Box1.breadth;
            Console.WriteLine("Volume of Box1 : {0}", volume);

            // volume of box 2
            volume = Box2.height * Box2.length * Box2.breadth;
            Console.WriteLine("Volume of Box2 : {0}", volume);

            Console.ReadKey();
        }
    }
}

OutPut:





Share this


0 Comments

Advertisement