美好的一天!这个问题似乎很容易,但我想不出怎么做.我会将Type参数传递给function并检查变量是否具有该类型.
void foo(Type type = ) // how to pass here default value for example System.Object?
{
if (elem.GetType() is type)
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
编辑我有下一堂课
class Element {}
class ChildElementClass : Element {}
class SecondChildEleementClass : Element{}
Run Code Online (Sandbox Code Playgroud)
并且有Elements []数组,它存储所有三个类的元素
Element[] elements;
Run Code Online (Sandbox Code Playgroud)
所以,我会检索ChildElementClass的所有元素.我通过其他方式制作它,但它很有趣.
c# ×1