I\'m sure there must be a much better way of doing this. I\'m trying to do a count operation on a Flags enum. Before I was itterating over all the possible values and counting t
There's a straight-forward way using functional programming (LINQ):
var skillCount = Enum .GetValues(typeof(Skills)) .Cast() .Count(skills.HasFlag);
It might be a bit slower than the bit-juggling solutions, but it's still allocation-free, has a constant run-time and is more intuitive.