我有以下類:不能因訪問級別保護訪問變量
class Department
{
private string departmentId;
private string departmentName;
private Hashtable doctors = new Hashtable();//Store doctors for
//each department
public Hashtable Doctor
{
get { return doctors; }
}
}
我有保存部門對象的數組列表:
private static ArrayList deptList = new ArrayList();
public ArrayList Dept
{
get { return deptList; }
}
我試圖讓所有的醫生(部門級Hashtable):
foreach (Department department in deptList)
{
foreach (DictionaryEntry docDic in department.Doctor)
{
foreach (Doctor doc in docDic.Value)//this is where I gets an error
{
if (doc.ID.Equals(docID))//find the doctor specified
{
}
}
}
}
但我無法編譯該程序。它給出了一個錯誤:
foreach statement cannot operate on variables of type 'object' because
'object' does not contain a public definition for 'GetEnumerator'
你應該使用這種泛型。請參閱[List](http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx)類。 –
Bernard