Defining a Class and create object out of it - CSharp Custom Type

CSharp examples for Custom Type:class

Introduction

The basic structure of a class follows this format:

class identifier
{
   class-body ;
}

identifier is the name given to the class, and class-body is the code that makes up the class.

A class with two data members

Demo Code

class point/*from   www . ja v  a  2  s  . com*/
{
   public int x;
   public int y;
}
class MainClass
{
   public static void Main()
   {
      point starting = new point();
      point ending   = new point();
      starting.x = 1;
      starting.y = 4;
      ending.x = 10;
      ending.y = 11;
      System.Console.WriteLine("Point 1: ({0},{1})", starting.x, starting.y);
      System.Console.WriteLine("Point 2: ({0},{1})", ending.x, ending.y);
   }
}

Result


Related Tutorials