Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 遍历接口列表_C# - Fatal编程技术网

C# 遍历接口列表

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

我有一个T型对象的接口

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();