0

I have an enum defined as

public enum SecurityRole
{
    Admin = 0,
    ViewLog = 1,
    DeleteLog = 2
}

and want to use the technique described here to get a List<SecurityRole>.

Thus the line

var lst = Enum.GetValues(typeof(SecurityRole)).Cast<SecurityRole>().ToList();

should work, but IntelliSense wont allow the .ToList property

I am using System.Linq. Is there some other reference I need?

Community
  • 1
  • 1
Kirsten
  • 15,730
  • 41
  • 179
  • 318
  • 1
    Your code is valid, and executes successfully. As a shot in the dark, maybe Visual Studio is confused? Are there compilation errors, or just IntelliSense failures? Try relaunching VS. – Michael Petrotta Mar 17 '13 at 06:45
  • @kirsten it works for me and this is the correct syntax, see the official question on this topic: http://stackoverflow.com/questions/1167361/how-do-i-convert-an-enum-to-a-list-in-c - Can you delete the `.` before `ToList()` and press the `.` if that fails press Ctrl+Space to bring up intellisense – Jeremy Thompson Mar 17 '13 at 07:07
  • just try to rebuild the solution and try again because ur code should work since you use: `using System.Linq` – Ahmed Magdy Mar 17 '13 at 07:43

2 Answers2

2

using System.Linq should do it. ToList() is an IEnumerable<T> extension method. Probably check if you have any other compilation errors in your code.

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
PSL
  • 123,204
  • 21
  • 253
  • 243
2

Check the solution here: How do I convert an enum to a list in C#?

Enum.GetValues(typeof(SomeEnum)).Cast<SomeEnum>();
Community
  • 1
  • 1
Ahmed Magdy
  • 5,956
  • 8
  • 43
  • 75