首页 > 解决方案 > 如何在接口中调用带有主体的方法

问题描述

我有一个接口定义为:

interface IProperty<T>
{
    public T Value { get;  set; }

    public T GetTheValue()
    {
        return (T)(Value);
    }
}

一个实现为:

class Animal : IProperty<string>
{
    public string Value { get;  set; }
}

用作:

var camel = new Animal { Value = "Camel" };

类的实例如何Animal访问接口GetTheValue()中的方法IProperty<T>?(IntelliSense 中没有显示任何内容)

如果不能,接口中带有主体的方法的目的是什么?

标签: c#inheritance

解决方案


推荐阅读