Article View: borland.public.csharpbuilder.language.csharp
Article #153Re: True Constants in C# ?
From: Bob Dawson
Date: Tue, 29 Aug 2006 04:16
Date: Tue, 29 Aug 2006 04:16
42 lines
1802 bytes
1802 bytes
"Dr. Bob Miller" wrote
>
> Is it possible to create and use true constants in C#? If so, could
someone
> scratch out a crude 10-line outline of an example? I'd really appreciate
> it!
Certainly you don't have to instantiate a class instance. Just declare your
constants as static, read-only properties, and the classname starts to
function like a logical grouping.
using System;
namespace Project2
{
class MathConst
{
public static double Pi
{
get{return 3.1427;}
}
public static string Lie
{
get{return "0 = 1";}
}
}
class Class
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Console.WriteLine(MathConst.Pi.ToString());
Console.WriteLine(MathConst.Lie);
Console.WriteLine((10 * MathConst.Pi).ToString());
Console.ReadLine();
}
}
}
Technical Details
Message-ID:
<44f3b155$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshub.sdsu.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<44f3aab7$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,1326b8d2515daa80 X-Google-Attributes: gid1efe35,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Bob Dawson" <RBDawson@prodigy.net> Newsgroups: borland.public.csharpbuilder.language.csharp References: <44f3aab7$1@newsgroups.borland.com> Subject: Re: True Constants in C# ? Date: Mon, 28 Aug 2006 22:16:00 -0600 Lines: 44 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1807 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1807 NNTP-Posting-Host: 63.230.158.125 Message-ID: <44f3b155$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1156821333 63.230.158.125 (28 Aug 2006 20:15:33 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshub.sdsu.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail