Do calculation on class data members - CSharp Custom Type

CSharp examples for Custom Type:Field

Description

Do calculation on class data members

Demo Code

public class Circle
{
   public int x;
   public int y;
   public int radius;
   public double area()
   {//from w w  w  .j  a  v a 2 s.co  m
      double theArea;
      theArea = 3.14159 * radius * radius;
      return theArea;
   }
   public double circumference()
   {
      double theCirc;
      theCirc = 2 * 3.14159 * radius;
      return theCirc;
   }
   public Circle()
   {
      x = 5;
      y = 5;
      radius = 1;
   }
   public void print_circle_info()
   {
      System.Console.WriteLine("\nCircle: Center = ({0},{1})", x, y);
      System.Console.WriteLine("        Radius = {0}", radius);
      System.Console.WriteLine("        Area   = {0}", area());
      System.Console.WriteLine("        Circum = {0}", circumference());
   }
}
class CircleApp
{
   public static void Main()
   {
      Circle first  = new Circle();
      Circle second = new Circle();
      first.x = 10;
      first.y = 14;
      first.radius = 3;
      first.print_circle_info();
      second.print_circle_info();
   }
}

Result


Related Tutorials