假设我有一个名为components的对象列表:
List<object> components = new List<object>();
Run Code Online (Sandbox Code Playgroud)
假设它填充了类引擎,轮子,框架的对象.现在,我想创建一个将类作为参数的函数,如果列表具有该类的对象,则返回true.像这样:
public static bool HasComponent( *the class* ) {
foreach(object c in components) {
if(c is *the class*)
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
我该怎么做呢?可能吗?