Monday, 15 April 2013

c# - Convert an enum to List -



c# - Convert an enum to List<string> -

how convert next enum list of strings?

[flags] public enum datasourcetypes { none = 0, grid = 1, excelfile = 2, odbc = 4 };

i couldn't find exact question, enum list closest want list<string>

use enum's static method, getnames. returns string[], so:

enum.getnames(typeof(datasourcetypes))

if want create method only 1 type of enum, , converts array list, can write this:

public list<string> getdatasourcetypes() { homecoming enum.getnames(typeof(datasourcetypes)).tolist(); }

c# .net enums generic-list

No comments:

Post a Comment