c# - Should static variables be replaced with enums? -


So I was looking at some code that was checked in and I was surprised at this:

  // Can not cancel the day's amount before cancellation {limit = 2}; After questioning that person, he argued that it is better to use Iman instead of the stable variable:  
  Private static int CANCELLATION_LIMIT = 2;  

So we started debating. My argument was that he was using Enum as a way to store the values ​​(it would break if there is a similar value with two values). He argued that this was an opponent for a stable variable in a class.

My question is how should best practice be used for either?

This is a way for you, where you must pass a certain position by some method, for example, you For example, the 'valid' argument for example:

  enum commandstate {pending = 1, ship = 2} public ILIList & lt; order & gt; GetOrdersInState (OrderState) {}  

This is a good example - to use the moments - when the orderstate is an intrate for which you create 2 crystals, then your The problem is that there is no restriction and are able to overcome invalid values.The compiler will not complain.

However, the case you are bringing up, I think using enums is not a valid solution It is misused to use an int, and a const int should be used.

Enums are good, but they should be used where they should be used. The tools are not one There is no antipatination in this case when there is a constant or static verb.


Comments