Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Shared constants
Message
De
15/08/2005 10:53:30
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
 
À
15/08/2005 06:36:37
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01040828
Message ID:
01040999
Vues:
16
Thanks; a class field seems like the ideal solution for my current needs.

>Hilmar,
>Besides ConfigurationSettings there is of course const class member. You could have your constants in a namespace like:
>
>
>namespace myApplication
>{
> class definitions
> {
>  public const string myConStr = "...";
> }
>}
>
>
>and refer to it as:
>myApplication.definitions.myConStr
>from anywhere. However like VFP if you change the value of myConStr, any other classes depending on the value should be recompiled. An alternative is readonly fields.
>
>
>namespace myApplication
>{
> class definitions
> {
>  public static readonly string myConStr = "...";
> }
>}
>
>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:
>
>
>namespace myApplication
>{
> class definitions
> {
>  public static readonly DataLocation myDataLoc = new DataLocation();
> }
> class DataLocation
> {
>   // fields
>   public DataLocation() {...}
> }
>}
>
>Cetin
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform