接口,泛型,c#

接口,泛型,c#,c#,generics,interface,C#,Generics,Interface,我对c#的了解很少 做以下事情的正确方法是什么 目标是创建一个带有getvalue()的接口,该接口可以跨多种结构工作 public interface IBOB { T GetValue<T>() where T:struct } class YAY:IBOB { public bool GetValue<bool>() { return true; } } 公共接口IBOB { T GetValue(),其中T:s

我对c#的了解很少

做以下事情的正确方法是什么

目标是创建一个带有
getvalue()
的接口,该接口可以跨多种结构工作

public interface IBOB 
{ 
    T GetValue<T>() where T:struct
}

class YAY:IBOB
{
    public bool GetValue<bool>()
    {
      return true;
    }
}
公共接口IBOB
{ 
T GetValue(),其中T:struct
}
YAY班:IBOB
{
公共bool GetValue()
{
返回true;
}
}

我怀疑你的意思是:

public interface IBOB<T> where T:struct
{ 
    T GetValue(); 
}

否则它与签名不匹配。

我怀疑你的意思是:

public interface IBOB<T> where T:struct
{ 
    T GetValue(); 
}

否则它与签名不匹配。

我们需要更多信息。我们需要更多信息。
class YAY : IBOB<bool>, IBOB<int>
{
    bool IBOB<bool>.GetValue() => true;
    int IBOB<int>.GetValue() => 42;
}
public bool GetValue<T>() {...}