Click here to Skip to main content
15,899,937 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
Foothill8-Jun-17 9:41
professionalFoothill8-Jun-17 9:41 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
carloscs8-Jun-17 11:23
carloscs8-Jun-17 11:23 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
Foothill8-Jun-17 11:34
professionalFoothill8-Jun-17 11:34 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
Mike Marynowski8-Jun-17 10:42
professionalMike Marynowski8-Jun-17 10:42 
GeneralRe: c# Const vs. Readonly, Scope, Usings PinPopular
Dan Neely7-Jun-17 4:51
Dan Neely7-Jun-17 4:51 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
Chris Maunder7-Jun-17 4:52
cofounderChris Maunder7-Jun-17 4:52 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
irneb8-Jun-17 5:41
irneb8-Jun-17 5:41 
GeneralRe: c# Const vs. Readonly, Scope, Usings PinPopular
OriginalGriff7-Jun-17 4:52
mveOriginalGriff7-Jun-17 4:52 
Quote:
Why can't I say
C#
const DateTime today = DateTime.Now;

Because DateTime.Now is not a compile-time constant, it's a run time property which returns an non-constant value.
Suppose it did allow it: what value should be in today?
The DatetIme when the app was started? When the assembly containing the code was loaded? When the class containing the constant value was statically initialized?
What would happen if two different classes (or worse assemblies) both declared the same value? Would they be the same? Should they be? How would the system decide for you?

That's the point of const vs readonly - the former is a compile time constant value, the later is a runtime constant value. That way, you have the choice for what exactly you want to do, rather than letting the system try to make up it's mind for you.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!

GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
lopatir7-Jun-17 5:41
lopatir7-Jun-17 5:41 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
TheGreatAndPowerfulOz7-Jun-17 5:43
TheGreatAndPowerfulOz7-Jun-17 5:43 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
Fabio Franco8-Jun-17 1:50
professionalFabio Franco8-Jun-17 1:50 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
TheGreatAndPowerfulOz8-Jun-17 4:48
TheGreatAndPowerfulOz8-Jun-17 4:48 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
Fabio Franco8-Jun-17 5:03
professionalFabio Franco8-Jun-17 5:03 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
TheGreatAndPowerfulOz8-Jun-17 5:22
TheGreatAndPowerfulOz8-Jun-17 5:22 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
Member 102778078-Jun-17 6:14
Member 102778078-Jun-17 6:14 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
Fabio Franco8-Jun-17 6:57
professionalFabio Franco8-Jun-17 6:57 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
pherschel7-Jun-17 6:12
pherschel7-Jun-17 6:12 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
TheGreatAndPowerfulOz7-Jun-17 6:57
TheGreatAndPowerfulOz7-Jun-17 6:57 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
Fabio Franco8-Jun-17 1:55
professionalFabio Franco8-Jun-17 1:55 
GeneralRe: c# Const vs. Readonly, Scope, Usings PinPopular
F-ES Sitecore7-Jun-17 5:18
professionalF-ES Sitecore7-Jun-17 5:18 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
Foothill7-Jun-17 8:50
professionalFoothill7-Jun-17 8:50 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
kalberts8-Jun-17 1:54
kalberts8-Jun-17 1:54 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
dandy727-Jun-17 5:21
dandy727-Jun-17 5:21 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
TheGreatAndPowerfulOz7-Jun-17 5:46
TheGreatAndPowerfulOz7-Jun-17 5:46 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
dandy728-Jun-17 3:45
dandy728-Jun-17 3:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Straw Poll

Were you affected by the geomagnetic storms this past weekend?
Communication disruptions, electrified pipes, random unexplained blue-screens in Windows - the list of effects is terrifying.
  Results   477 votes