C#动态列表名称

时间:2013-12-06 03:50:51

标签: c# .net

我需要在c#中创建一些列表,但是想根据某些条件动态命名这些列表。

例如

List<string> x1= new List<string>();
List<string> x2 = new List<string>();

名称“x1”和“x2”将在运行时出现(可能来自某个文件或其他内容)。有没有办法实现这个目标?

1 个答案:

答案 0 :(得分:11)

创建Dictionary<string, List<string>>

var dict = new Dictionary<string, List<string>>();

dict["x1"] = new List<string>();

您可以将"x1"替换为变量。