如何在控制台应用程序中实现 MVP?

发布于 2024-08-04 16:58:11 字数 304 浏览 1 评论 0原文

我在控制台应用程序的 Program.cs 中有以下代码

class Program : IView
{
  private static ViewPresenter _presenter;

  static void Main(string[] args)
  {
      _presenter = new ViewPresenter(this);  
  }
}

,但无法将 this 传递给演示者,因为 Main 方法是 static。现在我怎样才能做到这一点?

I have following code in Program.cs in console application

class Program : IView
{
  private static ViewPresenter _presenter;

  static void Main(string[] args)
  {
      _presenter = new ViewPresenter(this);  
  }
}

but I cant pass this to presenter, as Main method is static. Now how could I make this work ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故人爱我别走 2024-08-11 16:58:12

您必须创建一个 Program 实例。 Main 是一个静态方法。

class Program : IView {
    private static ViewPresenter _presenter;

    static void Main(string[] args) {
        _presenter = new ViewPresenter(new Program());  
    }
}

You have to create an instance of Program. Main is a static method.

class Program : IView {
    private static ViewPresenter _presenter;

    static void Main(string[] args) {
        _presenter = new ViewPresenter(new Program());  
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文