This:
string csvEnums = string.Join(",", Enum.GetNames(typeof(Bla)));
returns:
X1,Y1
given this enumeration:
public enum Bla
{
[Description("X")]
X1 = 1,
[Description("Y")]
Y1 = 2
}
Is there a similar efficient way to obtain the comma separated list:
1,2
Try casting GetValues()
return array to int
s:
string csvEnums = string.Join(",", Enum.GetValues(typeof(Bla)).Cast<int>());
The problem with GetValues()
method is that returns an object of type Array
, and there are no Join()
overload that can process it correctly.
Try this:
string csvEnums = string.Join(",", Enum.GetValues(typeof(Bla)).Cast<Bla>().Select(x=>(int)x));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With