Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Global Variables C#
Message
From
12/12/2009 15:11:12
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 3.0
Miscellaneous
Thread ID:
01438724
Message ID:
01438778
Views:
58
>>>Cetin.
>>>
>>>I have a class like this called myAppConstants, but I'm interesting in variables, not constants, that span all forms
>>>A good example is the ID of the user who logs into the application.
>>>All forms need that information.
>>>I'm rolling it forward from form to form using properties.
>>>Am I missing something?
>>>
>>>
>>>
>>>
>>>
>>>>>you again refer to it as:
>>>myApplication.definitions.myConStr
>>>
>>>However if value is changed it's only 'definitions' class that you need a recompile (other classes obtain value at runtime despite compile time if it's a field and not a constant). Also with constants and fields you're not limited to simple types and could get the value using a method (and say read from a txt,xml file or ask to user etc). ie:
>>
>>Yes, you are missing that I suggest an alternative to constants in that message's question. Sample shows readonly which instead you might use read/write property.
>>Cetin
>
>That is suggested by Bill Wagner as well in his excellent books "Effective C#" and "More Effective C#". In fact it is the second of 50 tips in the first book: "Prefer readonly to const".
>
>Good books, BTW. The second one focuses on new features in C# 3.0 and 3.5. He is probably running like a hamster on a wheel on another volume, covering C# 4.0, even as we speak ;-)

I hope to read those books and at the moment I am doing some Silverlight 4 with WCF services on 4.0:)
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform