Article View: borland.public.csharpbuilder.language.csharp
Article #160Re: True Constants in C# ?
From: Dr. Bob Miller
Date: Wed, 30 Aug 2006 11:44
Date: Wed, 30 Aug 2006 11:44
48 lines
2498 bytes
2498 bytes
> But declaring public fields, not marked as const, should still be a real
> no-no.
Well, this whole thing has shore been a lesson to me!
Many thanks to all who responded. This is why the Borland (Devco?)
community is so great!
Best regards,
Dr. Bob Miller
"Joanna Carter [TeamB]" <joanna@not.for.spam> wrote in message
news:44f555aa@newsgroups.borland.com...
> "Marc Rohloff [TeamB]" <"on request"> a οΏ½crit dans le message de news:
> 1j04hi3wixlhw.dlg@dlg.marcrohloff.com...
>
> | class MyClass
> | {
> | public int x;
> | public static readonly int c2 = 5;
> | }
> |
> | public static void Main()
> | {
> | Console.WriteLine("c1 = {0}, c2 = {1}", MyClass.c1, MyClass.c2
> | Console.WriteLine("c1*4 = {0}, c2*4 = {1}", MyClass.c1*4, MyClass.c2*4
> | );
> |
> | In the second WriteLine the compiler will pre calculate the value 20,
> | for c2 it will perform the calculation on each execution.
> |
> | A couple of points 'const' fields are automatically static and
> | read-only.
>
>
> Yes, I had forgotten that they were static, even if not declared as such.
> But declaring public fields, not marked as const, should still be a real
> no-no. Bob's suggestion of read-only properties is a valid solution, for
> those who don't mind typing :-)
>
> Joanna
>
> --
> Joanna Carter [TeamB]
> Consultant Software Engineer
>
>
Technical Details
Message-ID:
<44f57a06@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news4.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> <1j04hi3wixlhw.dlg@dlg.marcrohloff.com> <44f555aa@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,1326b8d2515daa80 X-Google-Attributes: gid1efe35,public X-Google-Language: ENGLISH,ASCII Reply-To: "Dr. Bob Miller" <drbob@tracesystemsinc.com> From: "Dr. Bob Miller" <drbob@tracesystemsinc.com> Newsgroups: borland.public.csharpbuilder.language.csharp References: <44f3aab7$1@newsgroups.borland.com> <1j04hi3wixlhw.dlg@dlg.marcrohloff.com> <44f555aa@newsgroups.borland.com> Subject: Re: True Constants in C# ? Date: Wed, 30 Aug 2006 07:44:00 -0400 Lines: 50 Organization: Trace Systems, Inc. X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2869 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 68.48.46.9 Message-ID: <44f57a06@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1156938246 68.48.46.9 (30 Aug 2006 04:44:06 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news4.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