C# 遍历接口列表
我有一个T型对象的接口C# 遍历接口列表,c#,C#,我有一个T型对象的接口 public interface IService<T> 公共接口iSeries设备 我有一堆不同类型T的接口。如何将这些接口添加到某种类型的列表中,遍历列表并调用接口使用的公共方法。有什么想法吗?有没有其他办法 如果我将其添加到列表中,我就看不到正确转换类型t的方法。如果该方法是通用的,那么它可能不依赖于t,因此您应该能够执行以下操作: interface IService { void TheMethod(); } interface ISer
public interface IService<T>
公共接口iSeries设备
我有一堆不同类型T的接口。如何将这些接口添加到某种类型的列表中,遍历列表并调用接口使用的公共方法。有什么想法吗?有没有其他办法
如果我将其添加到列表中,我就看不到正确转换类型t的方法。如果该方法是通用的,那么它可能不依赖于
t
,因此您应该能够执行以下操作:
interface IService {
void TheMethod();
}
interface IService<T> : IService {
// other stuff
}
foreach(var svc in list) svc.TheMethod();