如何在 C# 中的控制台应用程序中设置启动对象? [英] How to set startup object in console application in C#?

查看:37
本文介绍了如何在 C# 中的控制台应用程序中设置启动对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这并不难,但我仍然面临一个问题,我创建了一个名为 Console Application 的控制台应用程序,在这个应用程序下,有两个类,一个是 Program.cs,Delegate.cs.当我尝试运行 Delegate.cs 但始终运行 Program.cs 时.甚至我试图从属性设置启动对象但是 Delegate.cs 没有出现在下拉列表中.代码在这里---

I know this is not tough but still I am facing a problem, I have created one console application Named Console Application, Under this application, there are two class one is Program.cs, Delegate.cs. When I am trying to run Delegate.cs but always running Program.cs. Even I tried to set the startup object from properties But there Delegate.cs is not appearing in Drop Down List. A code is here---

class program
{
   public static  void Main()
   {
    Console.WriteLine("I am from program.cs");
   }

}

class Delegate
{
   public static  void Main()
   {
    Console.WriteLine("I am from Delegate.cs");
   }
}

我使用的是 Visual Studio 2015.

I am using Visual Studio 2015.

推荐答案

也许你需要:

  1. 先编译(Ctrl+Shift+B)

用另一个词代替Delegate

尝试给你的方法一个 args 参数 Main(string[] args)

Try giving your method an args parameter Main(string[] args)

它对我有用:

这篇关于如何在 C# 中的控制台应用程序中设置启动对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆