Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Public constant
Message
 
 
À
18/03/2013 12:56:49
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01568710
Message ID:
01568719
Vues:
39
>>>>Hi everybody,
>>>>
>>>>I've defined this constant in the class declaration
>>>>
>>>>
>>>>public const String EncodingXMLString
>>>>
>>>>
>>>>but I can not access it by ClassName.ConstName
>>>>
>>>>I can change it to be a readonly static property instead, but why I can not use it as a constant? I see a comment by another colleague on another readonly property
>>>
>>>
>>>Because your definition does not make it a constant
>>>
>>>A constant expression is an expression that can be fully evaluated at compile time
>>>
>>>
>>>>// Huh! Can't use const here - weird.
>>>>
>>>>Indeed weird - do you see what may be wrong?
>>>>
>>>>Thanks in advance.
>>
>>So, what is wrong exactly here - why it can not be evaluated in compile time?
>>
>>
>>      internal static readonly String EncodingXMLString = @"<?xml version = ""1.0"" encoding=""Windows-1252"" standalone=""yes""?>";
>>
>>I already switched to the readonly property since constant didn't work.
>
>
>That shouldn't be a problem
>
>	internal class Defs
>	{
>		internal const String EncodingXMLString = @"<?xml version = ""1.0"" encoding=""Windows-1252"" standalone=""yes""?>";
>	}
>
Didn't work for me - I was unable to access this constant from another class - but I think I know what I was doing wrong - I was trying to access it using class name instance instead of the Type instance. Because when I got similar error using that property I switched to Database.Property instead of database.Property (where Database is the class name while database is the class instance name).

Do you think that was the original problem?
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform