Try the following code
public enum Color
{
Blue=1,
Red=2,
Green=3
}
public List<Color> ConvertColorEnum()
{
var intColor = new List<int>(){1,2,3};
return intColor.Cast<Color>().ToList();
}
Do you think the ConvertColorEnum() will return a list of color, i.e., List<Color>(){Color.Blue, Color.Red, Color.Green}?
I tested this on 2 machines, one with .net 3.5 ( mscorlib version 2.0.50727.1433), another with .net 3.5 SP1 ( mscorlib version 2.0.50727.3082). The results were different– the .net 3.5 threw an InvalidCastException because couldn’t convert integer to enum, whereas .net 3.5 SP1 could run successfully, with correct results returned.
Anyone would like to try this on his/her machine and report the result or explain why this is so?
You can read about the difference between the SP1 and the original release of the .net 3.5 framework in the release notes.
Here’s what it says for this particular issue:
You can also get more details in this blog post.