Is it possible to declare global constants? That is, constants available in all classes? When I try to declare a constant outside the class, as with the enumeration, I get a parsing error.
I have been using enums this way for a while, but enums are limited to integers, and I would like to use easy-to-use words instead of float values.
Example; I would like the following to be available in any class:
const float fast = 1.5f;
const float normal = 1f;
const float slow = .75f;
I know I can get around this by creating enum (Speed) for speed names, and then creating a static SpeedNum () method that reads enum Speed ββand returns the associated value, but it takes so much extra writing every time and I was hoping for something more elegant:
Example:
public double function SpeedNum(Speed speed)
{
switch (speed)
{
case speed.fast :
return 1.5;
case speed.normal :
return 1f;
case speed.slow :
return .75f;
}
source
share