c# - 不实现接口(interface)成员问题

标签 c# interface

我有:

public interface ITest
{
    string test { get; set; }
}

[DataContract]
public class TestGeneric : ITest
{
    [DataMember]
    public string test;
}

但我不断收到错误消息:'TestGeneric' 没有在 public class TestGeneric 中的 TestGeneric 上实现接口(interface)成员 'ITest.Test' : ITest 代码行。有人能解释这是为什么吗?

最佳答案

您已经创建了一个字段,因为您省略了 { get;放; 使成员成为属性的访问器。

实现必须与接口(interface)完全匹配,所以添加那些访问器:

public class TestGeneric : ITest
{
    public string Test { get; set; }
}

关于c# - 不实现接口(interface)成员问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27826391/

相关文章:

c# - 返回类实现的接口(interface)类型 C#

c# - 是否可以将基于接口(interface)的模拟转换为对象?

c# - 没有匹配项时的 LINQ 结果?

c# - 将方法转换为 Linq 表达式以供查询

java - 一个对象的两个接口(interface)的命名约定

c# - MVC 模型绑定(bind)到接口(interface)

c# - 以编程方式将用户名和密码发布到登录页面

c# - 在格式错误的 xml 中转义属性中的内部引号

c# - 按 linq 中的特殊枚举值排序列表

go - 接口(interface)中的相同结构