Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Constants (such as 1 or 0) -> Int16 ?
Message
From
25/04/2014 15:09:14
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01599064
Message ID:
01599085
Views:
37
Likes (1)
>>No, that's a magic number.
>>
>>The constant needs to be defined earlier
>>
>>const short maxAdmissionDays = 1;
>>DateTime admission_end = this.dtScan.Date.AddDays(Math.Max(admissions, maxAdmissionDays).AddSeconds(-1);
>>
>>
>Hmm, is it good practice? I can probably use this idea (the constant name should be min, though).
>
>Thanks again.
>
>Also, where and how should I declare it? At the top of the class code?

One thing to bear in mind:

If the constant will be used in different DLL's then changing the constant and re-compiling the DLL where it is declared will leave the old value in other DLLs.
Better to use 'public static readonly' - that way other DLLs will pick up the new value.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform