Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Global consts not allowed?!
I just discovered that C# won't let me declare a constant at the
namespace level. My app has a group of classes that need to share
string constants, and it seems like perfectly reasonable thing to
declare these at the namespace level. Apparently, Microsoft thought
otherwise.

This seems like a totally unnecessary, and frustrating constraint. Why
are namespace constants disallowed, but namespace enums are not? An
enum is conceptually the same thing (with the inconvenient restriction
of being only integer based).

This anti-feature adds no value to the language, and just forces
programmers to resort to cumbersome workarounds. If you really want
global constants you can still achieve the effect by declaring them as
static members of a struct. The resulting syntax looks a lot like
enums.

Now that I've vented my frustration I feel better, so I'll go an
structurize all my constants.

Aleko


Report this thread to moderator Post Follow-up to this message
Old Post
Aleko
05-04-05 01:57 AM


Re: Global consts not allowed?!
I was surprised by this, too. However, I find a year on that I have
very little use for "free-floating" constants that aren't associated
with any class. Most constants belong as part of a class definition,
just for the sake of clarity.

I say "most". On odd occasion I have a constant or two that really
don't belong with any particular class, but need to be globally
accessible. That's when I make them members of a sealed utility class.

I you have that many free-floating, global constants, I have trouble
believing that none of them logically belongs with any class. If, as
you say, they're specific only to one particular application, then why
not put them in the class that holds your Main method?


Report this thread to moderator Post Follow-up to this message
Old Post
Bruce Wood
05-04-05 01:57 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

C# archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 09:53 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.