c# - Should static properties in a Constants class implement backing fields? -


I have a class constraint, in which I store many stable readonly variables.

What should I do:

  Only for private static reading, int _maxThings = 100; ... Public Stable Int Maxings {Meet {Return _ Max Tips; }}  

This seems unnecessary to me. Is there any reason I just do not do the following?

  Public Fixed In Maxings {get {return 100; }}  

edit

OK, so this was the brain's fart of a question. I think this issue is that if I am going to set this value in initialization, then it uses a static backing field and a public exposes only the property which will not need to be static.

If I am comfortable in setting up a public stable property for a hard price, there is no functional difference between them and just have to cook it in the assembly. As long as I do not remember any other concept, in this case I only use a const.

Thanks for the reply.

you should

public const int maxThings = 100;

There is no reason why I can look at the properties in this case to use.

Update ->

In response to comments .. If you are developing a library and exporting constants, it is important to understand how the constants are consumed. When the net is compiled against your library, continuous values ​​are underlined and the consumer is included in the application, such as your library is not and consumer application is then the old stable Price will still exist. This, of course, should be used when the stable properties are used.

If you are not developing a library, use const is okay.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -