說我有調用的組件對象的列表:如何檢查什麼類是在C#中的對象
List<object> components = new List<object>();
說,這是與類發動機,車輪,車架的對象填充。現在,我想創建一個將類作爲參數的函數,如果列表中有該類的對象,則返回true。像這樣:
public static bool HasComponent(*the class*) {
foreach(object c in components) {
if(c is *the class*)
return true;
}
return false;
}
我該怎麼做呢?可能嗎?
靜態方法。 ...來自實例的電話..... upvoters是「天才」 –
大寫只爲你。 – Femaref
非常感謝您的幫助 – user1494136