Jam*_*ech 1 c# sqlite xamarin.ios ios
对于某人来说,这很可能是一个非常基本的问题,但我无法理解它.基本上我有一个List的自定义类:
public class CorrectiveMaintResults
{
public string Comment { get; set; }
public string Cleared { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我最终将它存储在一个数据库中,我在每个项目之间放置一个换行符分隔符,用于注释和清除.然后我检索这个以放回到表中.为了实现这一点,我创建了两个私有列表,它们从db中获取注释和清除数据.
我想要做的是创建一个for或foreach循环,将私有列表添加回我的自定义列表(correctiveMainResults).这就是我想要的:
for (int i = 0; i < correctiveMainComment.Count; i++)
{
maintResults.Comment = correctiveMainComment[i];
maintResults.Cleared = correctiveMainCleared[i];
FormResults.correctiveMainResults.Add(maintResults);
}
Run Code Online (Sandbox Code Playgroud)
mainResults是我初学的类:
CorrectiveMaintResults maintResults = new CorrectiveMaintResults();
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,当结果被添加到了FormResults.correctiveMainResults,它只是似乎每个列表的最后一个索引,只是复制它.
希望有人可以帮助或理解我的意思.没有实际看到应用程序运行很难解释.
您只在循环外创建一个对象.尝试这样的事情:
for (int i = 0; i < correctiveMainComment.Count; i++) {
CorrectiveMaintResults maintResults = new CorrectiveMaintResults();
maintResults.Comment = correctiveMainComment[i];
maintResults.Cleared = correctiveMainCleared[i];
FormResults.correctiveMainResults.Add(maintResults);
}
Run Code Online (Sandbox Code Playgroud)