Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
434 views
in Technique[技术] by (71.8m points)

c# - interface List Error "does not implement interface member"

I'm expanding on my previous question, which was solved. How to call Method's Class Name dynamically?

interface IVideoCodec works with void Methods successfully, but it is not working with List.

VP8 Class gives the error 'VP8' does not implement interface member 'Controls.IVideoCodec.test'

VP8 Class Error


File: 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
        }
    }
}
File: VP8.cs
namespace Controls.Video.Codec
{
    public class VP8 : Controls.IVideoCodec // <-- Gives Error
    {
        public List<string> test = new List<string>()
        {
            "1",
            "2",
            "3"
        };

        public void Example()
        {
            //...
        }
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In your interface you declare a property but in VP8 you have a field. Change it to

public class VP8 : Controls.IVideoCodec // <-- Gives Error
{
    public List<string> test  {get; set;} = new List<string>()
    {
        "1",
        "2",
        "3"
    };

    public void Example()
    {
        //...
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...