我正在尝试查看是否可以在比较中在变量中使用 System.Type。我有以下代码:
internal ObservableCollection<FREQUENCY> GetFrequencies(System.Type equipmenttype)
{
...
foreach (var incident in query)
{
if (typeof(equipmenttype).IsSubclassOf(typeof(incident)))
{
foreach (var freq in incident.FREQUENCY)
{
freqs.Add(freq);
}
}
}
return freqs;
}
但是变量 'tmp' 和 'equipmenttype' 拉出错误“找不到类型或命名空间名称 'tmp'(您是否缺少 using 指令或程序集引用?)”
我知道这通常通过 typeof(MYCLASS) 来使用,但我很好奇这是否可以使用 System.Type 的变量,或者是否有任何方法可以做到这一点。谢谢。