首先,您的程序是从坏的方面采取的。我建议开始制作新的。动态命名“变量”的一种方法是创建类对象并编辑它们的属性。
这是我作为起始平台所做的:
首先,我创建了一个名为 set 的类
class set
{
public string ID { get; set; }
public List<int> numbers { get; set; }
}
然后我编写了将整个文本文件排序到这些类列表中的代码:
List<set> Sets = new List<set>();
string textfile = "your text file";
char[] spliter = new char[] { ',' }; //switch that , to whatever you want but this will split whole textfile into fragments of sets
List<string> files = textfile.Split(spliter).ToList<string>();
int i = 1;
foreach (string file in files)
{
set set = new set();
set.ID = i.ToString();
char[] secondspliter = new char[] { ',' }; //switch that , to whatever you want but this will split one set into lone numbers
List<string> data = textfile.Split(secondspliter).ToList<string>();
foreach (string number in data)
{
bool success = Int32.TryParse(number, out int outcome);
if (success)
{
set.numbers.Add(outcome);
}
}
i++;
Sets.Add(set);
}
希望它可以帮助某人。