PC Review


Reply
Thread Tools Rate Thread

const in .cs

 
 
stef
Guest
Posts: n/a
 
      3rd May 2007
Hello

I would like to use const declaration in the same manner as C does (in
a .h file)
How can I do that ?

For now, I declare a class which contains only all my const
declarations... but sounds bad

Do you have any ideas ?


thanks...

 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      3rd May 2007
On May 3, 3:39 pm, stef <stef.pellegr...@gmail.com> wrote:
> I would like to use const declaration in the same manner as C does (in
> a .h file)
> How can I do that ?
>
> For now, I declare a class which contains only all my const
> declarations... but sounds bad
>
> Do you have any ideas ?


Group your constants by their natural area - so "Pi" naturally lives
in the "Math" class, whereas the minimum value of a double is in the
"Double" class etc.

Jon

 
Reply With Quote
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      3rd May 2007
Stef,

Generally speaking, you should declare your constants where they make
sense. If you have a constant that is particular to a class, you should
declare it with that class, and not with a separate class just for
constants. Context is important here, I believe.

C# does not have the concept of a header file. If you need to use a
constant that is defined in a class in another assembly, then you need to
reference that assembly.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

"stef" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello
>
> I would like to use const declaration in the same manner as C does (in
> a .h file)
> How can I do that ?
>
> For now, I declare a class which contains only all my const
> declarations... but sounds bad
>
> Do you have any ideas ?
>
>
> thanks...
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get Const. Name =?Utf-8?B?QW1qYWQ=?= Microsoft VB .NET 2 13th Jan 2006 07:53 PM
const Jeff Louie Microsoft C# .NET 1 16th Nov 2005 08:22 AM
Casting from non-const to const (C2440) RalphTheExpert Microsoft VC .NET 1 14th Nov 2005 07:48 PM
friend CStringT operator+(const CStringT& str1, const CStringT& st =?Utf-8?B?VG9ueU0=?= Microsoft VC .NET 2 3rd Nov 2004 01:09 PM
Re: crash changing const to public const BrianB Microsoft Excel Programming 0 4th Aug 2003 10:13 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:39 AM.