I have this enumeration:
public enum SymbolPair
{
AUDJPY = 0, AUDNZD, AUDUSD, CADJPY, CHFJPY, EURCHF, EURGBP, EURJPY, EURUSD, GBPJPY, GBPUSD, NZDUSD, USDCAD, USDCHF, USDJPY
}
And I have a collection of symbol strings
List<string> symbols = new List<string>(){ };
Symbols are loaded into the collection dynamically depending on which symbols are entered in the input parameters. They can be loaded in any order and any count.
So for example one set can load in “EUR/USD”, “CHFJPY”, “GBPUSD”
I need to find the indexes corresponding to the index of the enumeration type. For example in this case I need the indexes 8, 4, and 10.
Can someone please give an idea how to do this with linq or delegates or any other efficient way.
Thanks
EDIT: I need something along these lines but this doesn’t work since linq does return a single value. How can I get that single index?
SymbolPair[] enumList = (SymbolPair[])Enum.GetValues(typeof(SymbolPair));
foreach (string symbol in symbols)
{
int instrumentIndex = from symbolPair in enumList
where symbolPair.ToString() == symbol
select (int)symbolPair;
}
Ok i got it. Thanks anyways.