這裏是我正在嘗試工作。foreach語句不能對類型爲
List<MasterEmployee > masterEmployee = new List<MasterEmployee >();
masterEmployee = MasterEmployee.GetAll("123"); //connecting db and returning a list...
foreach (MasterEmployee item in masterEmployee)
{
foreach (Registration reg in item.Registration) //<<<error here...
{
//
}
}
錯誤的位置:
Error 2 foreach statement cannot operate on variables of type Registration because Registration does not contain a public definition for 'GetEnumerator'
我有一個名爲MasterEmployee類,並在它我有一個很少的道具和一些方法就可以了
[Serializable]
public class MasterEmployee
{
//few props omitted ....
protected Registration _registration;
[CopyConstructorIgnore]
public Registration Registration
{
get
{
return _registration;
}
set
{
this._registration = value;
}
}
protected User _user;
[CopyConstructorIgnore]
public User MyUser
{
get
{
return _user;
}
set
{
this._user= value;
}
}
protected Student _student;
[CopyConstructorIgnore]
public Student Student
{
get
{
return _student;
}
set
{
this._student = value;
}
}
}
那麼最新的解決方案是什麼? –
@阿布 - 首先澄清你想要做什麼,然後從那裏開始。正如我所指出的,我真的不認爲你實際上希望'Registration'是一個包含'Registration'實例列表的可迭代類。你可能想要使用類似'ArrayList'的東西,並將你的'Registration'實例放在那裏。然後你迭代* list *,而不是'Registration'。 – aroth
你有沒有看過數據模型類的禮儀,所以我想要實現的是如何迭代列表......這就是註冊...學生......等等...... –