[英]C# Add List To List
I have some ViewModel like this. 我有一些这样的ViewModel。
public class ModelResult
{
public string NAME { get; set; }
public List<DataPointVM> RESULTs { get; set; }
}
public class DataPointVM
{
private float v1;
private float v2;
public DataPointVM(float v1, float v2)
{
this.TIME = v1;
this.VALUE = v2;
}
public float TIME { get; set; }
public float VALUE { get; set; }
}
Then, I have a list key 然后,我有一个清单键
List<string> parameterList = new List<string>(new string[] {
"Jhon",
"Andy",
"Ivan",
"Erick",
});
DataPoint ViewModel will store data like [{"Car1":"Bentley"},{"Car2":"Ferarri"}]
DataPoint ViewModel将存储数据,例如
[{"Car1":"Bentley"},{"Car2":"Ferarri"}]
I try with this code but the result is only display last key (Erick) example: [{"NAME":"ERICK","RESULTs":[{"car1":"xxx"},{"car2":"yyy"}]}]
我尝试使用此代码,但结果仅显示最后一个键(Erick)示例:
[{"NAME":"ERICK","RESULTs":[{"car1":"xxx"},{"car2":"yyy"}]}]
ModelResult mdlres = new ModelResult();
for (index=0;index<parameterList.Count();index++)
{
List<DataPointVM> points = new List<DataPointVM>();
mdlres.NAME = parameterList[index];
for (int i = 0; i < 2; i++)
{
points.Add(new ViewModels.DataPointVM(tVal[i], rVal[i]));
}
mdlres.RESULTs = points.ToList();
}
return mdlres;
I want to get all listkey with the details. 我想获取所有带有详细信息的列表键。
I'm sorry for my thread, but I've solve my problem. 很抱歉,我已经解决了我的问题。
ModelResult mdlres = new ModelResult();
// insert detail into detail list
// exit loop
newList.mresult.Add(mdlres); create collection of mdlres
My code have been published here: https://pastebin.com/uB2n6X3C 我的代码已在此处发布: https : //pastebin.com/uB2n6X3C
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.