の変数に対しては動作できません。ここでは、私は働こうとしています。ここ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;
}
}
}
だから問題の解決方法は? –
@Abu - まずあなたがしようとしていることを明確にし、そこから行ってください。私が指摘したように、実際には 'Registration'を' Registration'インスタンスのリストを含む反復可能なクラスにしたいとは思っていません。おそらく 'ArrayList'のようなものを使い、その内部に' Registration'インスタンスを置くことができます。次に、 'Registration'ではなく* list *を反復処理します。 – aroth
あなたはデータモデルクラスの儀式を見たことがありますので、達成するために何をすべきかは、リストを反復する方法です...登録の... thatsのconss ...学生....など... –