We can use const modifier to indicate that a field is a constant.
The following Math class has a constant field PI.
class Math
{
public const double PI = 3.14;
}
const field can be used in a method.
using System;
class Program
{
static void Main(string[] args)
{
const double PI = 3.14;
Console.WriteLine(2 * PI);
}
}
The output:
6.28
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |