我在C#中用兩種對象類型創建了一個列表,我需要顯示類型爲ClientPhysique
的對象。 ClientPhysique
和ClientMoral
擴展了Client
類。如何知道列表中的對象的類型?
public List<Client> Clients = new List<Client>();
#region Methodes
// Ajouter un Client:
public void Ajouter()
{
ClientPhysique CP = new ClientPhysique("EE111111", "Ahmed", "Yassine", 1, 06020202, "Rue Gmasa, Marrakech, 40000");
ClientMorale CM = new ClientMorale("A1414", "Rue mhamid, A6, Marrakech, 40160", 12121212, 1000000, 6, 06060606, "Titwan de Titwan");
Clients.Add(CP);
Clients.Add(CM);
}
'item.GetType()。Name'? – Berkay
「ClientPhysique和ClientMoral擴展了客戶端類。」那麼你們都已經知道在你的清單中只有'Cleint'級別的例子,不是嗎?那麼你的問題是什麼? – HimBromBeere
我沒有寫完整的代碼。項目表示列表內的項目。 @HimBromBeere – Berkay