小编Fru*_*gle的帖子

这是C#泛型错误吗?

此代码产生以下错误:

错误1'ConsoleApplication1.FooBar'未实现接口成员'ConsoleApplication1.IFoo.Bar'.'ConsoleApplication1.FooBar.Bar'无法实现'ConsoleApplication1.IFoo.Bar',因为它没有匹配的返回类型'ConsoleApplication1.IBar'.

interface IBar
{

}

interface IFoo
{
    IBar Bar { get; }
}

class FooBar<T> : IFoo where T : IBar
{
    public T Bar
    {
        get { return null; }
    }
}
Run Code Online (Sandbox Code Playgroud)

这不应该因为FooBar类中的where关键字而发生.

我使用Visual Studio 2013和.NET 4.5.1构建了它.

.net c# generics interface

3
推荐指数
1
解决办法
115
查看次数

标签 统计

.net ×1

c# ×1

generics ×1

interface ×1