tag:blogger.com,1999:blog-3606597030942128101.post4808740901393578467..comments2023-10-23T22:17:59.747+02:00Comments on Software Scenario: How to get the values of an enum?Snaitshttp://www.blogger.com/profile/09962823462714052499noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-3606597030942128101.post-10024008263168812512009-06-12T10:41:14.604+02:002009-06-12T10:41:14.604+02:00@Anonymous
Unfortunately, that's not right. E...@Anonymous<br /><br />Unfortunately, that's not right. Enum.GetValues does not accept a variable of type Enum. So this means you need to do a lot of different things instead of the line you're suggesting to remove.<br /><br />With your example you'd need to instanciate the Enum before passing it into the GetEnumValues, and you'd have to change the foreach-loop to do Enum.GetValues(enumType.GetType());<br /><br />In Stians example, you will not have to instanciate the enum, and since we don't need a particular instance of the Enum to get its values or names, we really just need the type. Hence Type t :)Yngve B. Nilsenhttps://www.blogger.com/profile/02774764185708808952noreply@blogger.comtag:blogger.com,1999:blog-3606597030942128101.post-40114184388099282772009-06-12T09:25:06.880+02:002009-06-12T09:25:06.880+02:00Hi,
If you change this line
GetEnumValues(Type t)...Hi,<br /><br />If you change this line<br />GetEnumValues(Type t)<br /><br />to<br /><br />GetEnumValues(Enum enumType)<br /><br />Then you don't need to do:<br />if (t.UnderlyingSystemType.BaseType == typeof(System.Enum))Anonymousnoreply@blogger.com