Given the enum
:
[Flags]
public enum mytest
{
a = 1,
b = 2,
c = 4
}
I've come up with two ways to represent all values in a single variable:
var OR1 = (mytest)Enum.GetNames(typeof(mytest)).Sum(a => (int)Enum.Parse(typeof(mytest), a));
var OR2 = (mytest)(typeof(mytest).GetEnumValues() as mytest[]).Sum(a => (int)a);
Now, although they both work, is there a neater way? Possibly a .NET method I'm missing?
Edit: For clarification, I need the function to be dynamic - I don't want to calculate it by specifying every single enum
value.