我想对组、语言和 TestEnum 的所有可能组合运行 GetResults()。如何使用 lambda 表达式重写此代码以避免使用 foreach 循环?
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();
}