유형의 변수에서 작동하지 않습니다. 여기서는 작동하려고합니다. 여기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' 인스턴스를 넣기를 원할 것입니다. 그런 다음 '등록'이 아닌 * 목록 *을 반복합니다. – aroth
당신은 데이터 모델 클래스의 라이트를 보았습니까? 그래서 iam tyring은리스트를 반복하는 것입니다. 등록의 ... thats consits of Registration ... Students .... so forth ... –