1

I'm looking to get the min and max value of an enum not the max amount of enumerators. I've seen Getting the max value of an enum

However, in Framework 4, cast() doesn't exist for GetValues().

Example:

public enum Foo
{
     Bird = 1,
     Cat = 2,
     Dog = 4,
     Hampster = 8
}

var last = Enum.GetValues(typeof(Foo)).Cast<int>().Max();

Result should be: 8

Anyone know how this is done in framework 4 without having to enumerate through it all myself?

Community
  • 1
  • 1
Chizl
  • 2,004
  • 17
  • 32

1 Answers1

4

IEnumerable.Cast<T>() is an extension method and was introduced in .NET 3.5

Are you missing a using System.Linq; statement?

You need that namespace to find the extension method.

Nick Butler
  • 24,045
  • 4
  • 49
  • 70