Article View: borland.public.csharpbuilder.language.csharp
Article #155Re: True Constants in C# ?
From: Joanna Carter [TeamB]
Date: Tue, 29 Aug 2006 15:19
Date: Tue, 29 Aug 2006 15:19
52 lines
2071 bytes
2071 bytes
"Dr. Bob Miller" <drbob@tracesystemsinc.com> a οΏ½crit dans le message de
news: 44f44eba$1@newsgroups.borland.com...
| I found I could shorten things down to one-liners by declaring the
constants
| as static
| fields, like so:
Noooooo!!!!!
This will not give you consts, it will give you public fields that can be
changed.
Try the following :
static void Main(string[] args)
{
MathConst.Pi = 654.89;
}
If you really want to save typing, at least use readonly fields.
namespace Project2
{
class MathConst
{
public static readonly double Pi = 3.1427;
public static readonly string Lie = "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();
}
}
}
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer
Technical Details
Message-ID:
<44f45b1b@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<44f3aab7$1@newsgroups.borland.com> <44f3b155$1@newsgroups.borland.com> <44f44eba$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 From: "Joanna Carter [TeamB]" <joanna@not.for.spam> Newsgroups: borland.public.csharpbuilder.language.csharp References: <44f3aab7$1@newsgroups.borland.com> <44f3b155$1@newsgroups.borland.com> <44f44eba$1@newsgroups.borland.com> Subject: Re: True Constants in C# ? Date: Tue, 29 Aug 2006 16:19:37 +0100 Lines: 54 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 NNTP-Posting-Host: 83.70.200.69 Message-ID: <44f45b1b@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1156864795 83.70.200.69 (29 Aug 2006 08:19:55 -0700) X-Authenticated-User: jcarter Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail