【问题标题】:How to Implement Interface methods into Another Project using Assembly reference in C#?如何使用 C# 中的程序集引用将接口方法实现到另一个项目中?
【发布时间】:2015-04-02 05:02:45
【问题描述】:

我正在创建 3 个项目:

  1. 控制台应用程序
  2. 接口APP
  3. 具体应用

从 InterfaceAPP 我声明了一些方法,例如,

interface IPerson
{
    void Method1();
    void Method2(int i);
}

在 ConcreteApp 中,我需要使用如下所示的 ASSEMBLY 参考来实现此接口方法

//This below code for direct reference. I need to get the methods an assembly reference 
class concrete : IPerson
{ 
    void Method1()
    { 
        Console.WriteLine("Concrete");
    }

    void Method2(int i)
    { 
        Console.WriteLine("Concrete");
    }
}

【问题讨论】:

  • 只需将它们定义为公共

标签: c# .net interface


【解决方案1】:
public interface IPerson
{
  void Method1();
  void Method2(int i);
}


public class concrete : IPerson
{ 
   public void Method1()
   { 
     Console.WriteLine("Concrete");
   }

   public void Method2(int i)
   { 
     Console.WriteLine("Concrete");
   }
}

【讨论】:

  • 谢谢。但是这段代码使用的是直接引用 InterfaceAPP.dll 。我需要使用远程程序集引用来实现这些方法。
  • 远程程序集引用是什么意思?
  • App1 & App2 是独立的应用程序。如果任何方法正在访问一个应用程序到另一个应用程序,则更早。我们正在添加要访问的直接引用。 App2-> 右键单击​​ Reference -> 添加 App1.dll 。所以现在我需要在 APPDOMAIN 中加载 APP2 程序集,然后访问这些程序集对 APP1 的引用。
  • 您可以将 .dll 文件添加到任何 .NET 应用程序中。我不明白这有什么问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-21
  • 2015-09-16
相关资源
最近更新 更多