.

Classes of C Sharp Assignment Help

CLASSES

  • classNameis a template which holds member variables and methods
  • The Objects of a classNameare instances of a className.
  • The methods and member variables forms a className.

classNameDefinition

  • The keyword classNameis used to declare a classNamefollowed by the classNamename;
  • The classNamebody covered by curly braces.

Classes of C Sharp Assignment Help By Online Tutoring and Guided Sessions from assignmenthippo.com


Syntax

access_ specifier classNameclass_name

{

access_ specifier data type variable1; // member variables

access_ specifier data type variable2;

access_ specifier return type method1(parameter_list) // member methods

{

{'// method body'}

}

}

where,

  • Access specifier specify the scope and visibility
  • The default access specifier for a classNametype is internal.
  • The default access specifiers of the members are private.
  • Data type specifies the variable type, and return type specifies the method return type
  • The dot (.) operator is used to access the classNamemembers.

Example

 using System;

namespace BoxApplication {

classNameArea {

public double length;

public double breadth; 

public double height;

}

classNameAreaMeasure {

static void Main(string[] args) {

Area a1 = new Area(); // Declare a1 of type Area

Area a2 = new Area(); // Declare a2 of type Area

double volume = 0.0; // Store the volume

a1.height = 5.0;

a1.length = 6.0;

a1.breadth = 7.0;

a2.height = 10.0;

a2.length = 12.0;

a2.breadth = 13.0;

 

{'// volume a 1'}

volume = a1.height * a1.length * a1.breadth;

Console.WriteLine("Volume of a1 : {0}", volume);

{'// volume a 2'}

volume = a2.height * a2.length * a2.breadth;

Console.WriteLine("Volume of a2 : {0}", volume);

Console.ReadKey();

}

}

}

Output:

Volume of a1 : 210

Volume of a2 : 1560

.