Illustrates the use of a const field : Constant : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » Constant »

 

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

  }

}

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» Constant