CSharp · Console
using System;
using System.Linq;
using System.Collections.Generic;
public class Program
{
public static List<T> SArrayEnumToList<T>(int[] arr)where T : struct, IConvertible
{
if (!typeof (T).IsEnum)
throw new ArgumentException("T must be of type System.Enum");
return arr.Cast<object>().Cast<T>().ToList();
}
public enum Test
{
blah,
balh2,
blah3
}
public static void Main()
{
var values = new int[]{0, 1, 2};
var results = SArrayEnumToList<Test>(values);
foreach (var result in results)
Console.WriteLine(result);
// or
Test[] foos = (Test[])(object)values;
foreach (var foo in foos)
Console.WriteLine(foo);
}
}