I would like to run GetResults() on all possible combinations of groups, languages and TestEnum. How can I re-write this code using lambda expressions to avoid using the foreach loops?
public enum TestEnum
{
ONE,
TWO,
THREE
}
public static void Test1()
{
List<string> groups = new List<string>() { "group1", "group2", "group3", "group4" };
List<string> languages = new List<string>() { "EN-CA", "FR-CA" };
List<string> results = new List<string>();
foreach (string group in groups)
{
foreach (string language in languages)
{
foreach (TestEnum enumval in Enum.GetValues(typeof(TestEnum)))
{
results.Add(GetResult(group, language, enumval));
}
}
}
}
public static string GetResult(string group, string language, TestEnum enumval)
{
return group + language + enumval.ToString();
}
GetValuesand then getting the string value of that, you can just useGetNames(that is, unless your real code uses the actual values, not just the string representations).