defining and using a constant in your program - CSharp Custom Type

CSharp examples for Custom Type:Constant

Description

defining and using a constant in your program

Demo Code

using System;/*  w w w . j a  v a 2 s.c o  m*/
class Program {
   static void Main(string[] args) {
      const double pi = 3.14159;
      // constant declaration
      double r;
      Console.WriteLine("Enter Radius: ");
      r = Convert.ToDouble(Console.ReadLine());
      double areaCircle = pi * r * r;
      Console.WriteLine("Radius: {0}, Area: {1}", r, areaCircle);
      Console.ReadLine();
   }
}

Result


Related Tutorials