I've been looking over some game programming code and have seen enums as in:
[Flags]
public enum CollisionCategories
{
Cat1 = (1 << 0),
Cat2 = (1 << 1),
Cat3 = (1 << 2),
Cat4 = (1 << 3),
...
}
Now, would this not be the same as just setting each item like 1, 2, 4, 8, ... ? I've seen the later as well. I know doing something like string s = string.Empty is better than string s = "" as far as performance goes but not sure about the enum.
Any thoughts?
Thanks much,
David
s = string.Emptyis just more expressive that's why people are using it, this has nothing to do with performance(1 << x)will be compiled to a constant so there is no performance differences. It is only because it might be easier to read(1 << 8)rather than256.