我需要在c#中创建一些列表,但是想根据某些条件动态命名这些列表.
例如
List<string> x1= new List<string>();
List<string> x2 = new List<string>();
Run Code Online (Sandbox Code Playgroud)
名称"x1"和"x2"将在运行时出现(可能来自某个文件或其他内容).有没有办法实现这个目标?
Mar*_*zek 11
创建Dictionary<string, List<string>>:
var dict = new Dictionary<string, List<string>>();
dict["x1"] = new List<string>();
Run Code Online (Sandbox Code Playgroud)
你可以"x1"用变量替换.