I'm probably not getting the question but I'm going to have a stab at this anyway.
To convert from a
String
to a
enum
the
Enum.Parse
method can be used (or if you want to be fault tolerant the
Enum.TryParse
).
By using
Linq it's easy to convert all
String
s in one array to
enum
in the other, like in this example;
using System;
using System.Linq;
namespace Sample {
enum Fruits {
Banana,
Apple,
Orange,
Pineapple
}
class Program {
static void Main(string[] args) {
var fruitStrings = new[] {"Banana", "Apple", "Pineapple", "Orange"};
var fruits = fruitStrings.Select(fs => (Fruits)Enum.Parse(typeof (Fruits), fs));
Console.WriteLine("Strings: {0}", String.Join(", ", fruitStrings));
Console.WriteLine("Enums : {0}", String.Join(", ", fruits));
}
}
}
Hope this helps,
Fredrik Bornander