C# 如何返回此IInfocard接口实例?

C# 如何返回此IInfocard接口实例?,c#,C#,我目前正试图在我的“createNewInfocard”函数中返回Iinforcard接口的一个实例,但是我一直遇到错误CS0266。我不确定如何解决这个问题 public interface IInfoCard { string Name { get; set; } string Category { get; } string GetDataAsString(); void DisplayData(Panel displ

我目前正试图在我的“createNewInfocard”函数中返回Iinforcard接口的一个实例,但是我一直遇到错误CS0266。我不确定如何解决这个问题

public interface IInfoCard
    {
        string Name { get; set; }
        string Category { get; }
        string GetDataAsString();
        void DisplayData(Panel displayPanel);
        void CloseDisplay();
        bool EditData();
    }




public interface IInfoCardFactory
{
    IInfoCard CreateNewInfoCard(string category);
    IInfoCard CreateInfoCard(string initialDetails);
    string[] CategoriesSupported { get; }
    string GetDescription(string category);
}

 public class Class1 : IInfoCardFactory
    {

    public IInfoCard CreateNewInfoCard(string category)
    {

        Class1 x;
        x = new Class1();
        return x;// i keep at getting error CS0266 at this return statement.
    }


}
Class1
必须实现
iInfo卡
接口,即

  public class Class1 : 
     IInfoCardFactory, 
     IInfoCard  // <- notice IInfoCard implementation
  {
     public IInfoCard CreateNewInfoCard(string category)
     {
        Class1 x;
        x = new Class1();
        return x;// i keep at getting error CS0266 at this return statement.
     }
     ...
     //TODO: put here IInfoCard methods and properties implementations
  }
公共类1:
我的工厂,

IInfoCard/您是否有实现
IInfoCard
接口的类

接口本身只是定义类应该具有的一些功能,因此您需要一个具体的实现来使用它:

// Notice the IInfoCard declaration, indicating Class1 implements it
public class Class1 : IInfoCardFactory, IInfocard
{
     /* Omitted for brevity */
}

这应该允许您从
CreateNewInfoCard()
方法返回
Class1
对象,因为它现在可以作为
IInfoCard
对象,因为它实现了它。

Class1不实现IInfoCard!你所犯的错误应该对你有意义。