Illustrates the use of a const field : Constant « Language Basics « C# / C Sharp






Illustrates the use of a const field

Illustrates the use of a const field
/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy

Publisher: Sybex;
ISBN: 0782129110
*/

/*
  Example6_2.cs illustrates the use of a const field
*/


// declare the Car class
class Car
{

  // declare a const field
  public const int wheels = 4;

}


public class Example6_2
{

  public static void Main()
  {

    System.Console.WriteLine("Car.wheels = " + Car.wheels);
    // Car.wheels = 5;  // causes compilation error

  }

}

           
       








Related examples in the same category

1.Illustrates the use of constantsIllustrates the use of constants