莫哈姆
新成员
- 已加入
- 2021年1月31日
- 留言内容
- 1
- 编程经验
- Beginner
我有一个错误,并且不知道如何解决该错误,它是:我有一个列表,该列表又是类型<List <String>>,使用构造函数,我要做的是保存某些信息,接下来编写的代码是:
然后在执行输出时得到以下信息:
我需要的是这样的输出:
有人可以告诉我错误在哪里,谢谢!
C#:
List<List<string>> opciones = new List<List<string>>();
public Opcion(){
var opcionesC = File.ReadAllText(this.dir).Split(";R;").ToList();
opcionesC.RemoveAll(item => item == "");
for(int i=0;i<opcionesC.Count;i++){
this.opciones.Add(new List<string>());
string[] opc= opcionesC[i].Split("\n");
foreach(var t in opc){
if(t.IndexOf("Marc")!=-1){
this.opciones[i].Add(t); //HERE ITS WORK
}
if(t.IndexOf("Model")!=-1){
this.opciones[i].Add(t.Remove(0,5)); //HERE IS THE PROBLEM, NOT ADDING
}
if(t.IndexOf("Tip")!=-1){
this.opciones[i].Add(t.Remove(0,3)); //HERE IS THE PROBLEM, NOT ADDING//El problema es esto, no se quiere añadir.
break;
}
}
}
}
C#:
Marca: Audi
Marca: BMW
C#:
Marca: Audi
Modelo: A4
Tipo: Turismo
Marca: BMW
Modelo: S3
Tip:...
附件
由主持人最后编辑: