C# 接口列表错误“;不实现接口成员“;
我在扩展我之前的问题,这个问题已经解决了C# 接口列表错误“;不实现接口成员“;,c#,C#,我在扩展我之前的问题,这个问题已经解决了 interface IVideoCodec可以成功地使用void方法,但不能使用List VP8Class给出错误'VP8'未实现接口成员控件.IVideoCodec.test' 文件:VideoControls.cs namespace Controls.Video { public class Controls { private static Dictionary<string, IVideoCodec&g
interface IVideoCodec
可以成功地使用void
方法,但不能使用List
VP8
Class
给出错误'VP8'未实现接口成员控件.IVideoCodec.test'
文件:VideoControls.cs
namespace Controls.Video
{
public class Controls
{
private static Dictionary<string, IVideoCodec> _vCodecClass;
private static void InitializeCodecs()
{
_vCodecClass = new Dictionary<string, IVideoCodec> {
{ "VP8", new Codec.VP8() },
{ "VP9", new Codec.VP9() },
{ "x264", new Codec.x264() },
{ "x265", new Codec.x265() }
};
}
public interface IVideoCodec
{
List<string> test { get; set; } // doesn't work
//void Example(); // works
}
public static void SetControls(string codec_SelectedItem)
{
InitializeCodecs();
List<string> example = _vCodecClass[codec_SelectedItem].test; // equal to Codec.VP8.test
//_vCodecClass[codec_SelectedItem].Example(); // equal to Codec.VP8.Example() // works
}
}
}
名称空间控件。视频
{
公共类控件
{
私有静态字典(vCodecClass);
私有静态void InitializeCodecs()
{
_vCodecClass=新字典{
{“VP8”,新的Codec.VP8()},
{“VP9”,新的Codec.VP9()},
{“x264”,新编解码器.x264(),
{“x265”,新的Codec.x265()
};
}
公共接口编解码器
{
列表测试{get;set;}//无效
//void Example();//有效
}
公共静态void SetControls(字符串编解码器\u SelectedItem)
{
初始化ecodecs();
列表示例=_vCodecClass[codec\u SelectedItem].test;//等于codec.VP8.test
//_vCodecClass[codec_SelectedItem].Example();//等于codec.VP8.Example()//有效
}
}
}
文件:VP8.cs
namespace Controls.Video.Codec
{
公共类VP8:Controls.IVideoCodec/在接口中声明属性,但在VP8中有字段。将其更改为
public class VP8 : Controls.IVideoCodec // <-- Gives Error
{
public List<string> test {get; set;} = new List<string>()
{
"1",
"2",
"3"
};
public void Example()
{
//...
}
}
public class VP8:Controls.IVideoCodec//您已将test
定义为VP8
类中的字段而不是属性..您需要test=>new
…谢谢,这修复了错误。我需要再做一些测试,我会回复您并标记为已解决。
public class VP8 : Controls.IVideoCodec // <-- Gives Error
{
public List<string> test {get; set;} = new List<string>()
{
"1",
"2",
"3"
};
public void Example()
{
//...
}
}