我的项目中有大约50个课程.每个类都有一些保存功能.现在我想将数据保存在一些所需的流程中.
EG: I have classes A, B, C, D, E.
And the sequence of save might be : C, D, E, B, A
Run Code Online (Sandbox Code Playgroud)
现在因为我有很多类,所以我想创建一个for循环来保存流中的数据.要做到这一点,我想创建一个类列表,然后我可以做这样的事情:
List<Classes> list_class = new List[] {C, D, E, B, A};
foreach (Classes item in list_class)
{
item.Save();
}
Run Code Online (Sandbox Code Playgroud)
是否有可能拥有这种功能?如果是,那怎么样?
编辑:
Below you can see what i want to achieve:
List<?> Saving_Behaviour = new list[];
for (int i = 0; i < Saving_Behaviour.Length; i++)
{
if (((Saving_Behaviour[i])Controller.GetBindingList()).HasValue())
{
(Saving_Behaviour[i]).Save();
//do save
}
}
Run Code Online (Sandbox Code Playgroud)
简介:在if语句中,每个类都检查其实例是否具有某些值.然后,如果它有一些值,它将调用该类的save方法.
我希望现在很清楚.