πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.csharpbuilder.language.csharp
Article #159

Re: True Constants in C# ?

#159
From: Joanna Carter [TeamB]
Date: Wed, 30 Aug 2006 09:08
32 lines
1870 bytes
"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: <44f555aa@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!newshub.sdsu.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <44f3aab7$1@newsgroups.borland.com> <1j04hi3wixlhw.dlg@dlg.marcrohloff.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> <1j04hi3wixlhw.dlg@dlg.marcrohloff.com>
Subject: Re: True Constants in C# ?
Date: Wed, 30 Aug 2006 10:08:48 +0100
Lines: 34
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: <44f555aa@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1156928938 83.70.200.69 (30 Aug 2006 02:08:58 -0700)
X-Authenticated-User: jcarter
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!newshub.sdsu.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail