简体   繁体   English

接口和泛型C#

[英]interface and generics C#

I have a interface like this: 我有一个像这样的界面:

public interface IMyInterface<T> where T:class
    {

        long OS { get; set; }

        T App { get; set; }
    }

and another interface like this: 和另一个像这样的界面:

public interface IMyInterfaces
    {
        List<IMyInterface<T>> Subscribers { get; set; } //this line give me error
    }

I got error 我有错误

You need to specify a concrete type or another generic parameter for T when you use IMyInterface<T> 使用IMyInterface<T>时,需要为T指定一个具体类型或另一个通用参数。

public interface IMyInterfaces
{
    List<IMyInterface<int>> Subscribers { get; set; }
}

OR 要么

public interface IMyInterfaces<TOther>
{
    List<IMyInterface<TOther>> Subscribers { get; set; }
}

Note I used TOther to stress that it is another generic parameter, different from the T in IMyInterface but you could use the same name ( T ) for TOther 请注意我用TOther强调,这是另一种通用的参数,从不同TIMyInterface ,但你可以使用相同的名称( T的) TOther

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM