簡體   English   中英

在VS c#console應用程序中更改源文件以編譯項目中的Main()方法

[英]Changing a source file to compile Main() method in a project, in VS c# console application

我有一個示例c#console項目,其中有2個程序文件:

  1. Program.cs中
  2. Program02.cs

Program.cs中,我有通常的main方法,它是項目的入口點:

public static void main(string[] args)
{
    Console.WriteLine("hello world from Program.cs");
}

但是我想從Program02.cs文件中執行程序,所以我在文件中添加了方法。

public static void main(string[] args)
{
    Console.WriteLine("hello world from Program02.cs");
}

顯然它不起作用,項目的入口點/執行從Program.cs開始,如何將主執行方法切換到Program02.cs文件?

在此輸入圖像描述在此輸入圖像描述

在此輸入圖像描述在此輸入圖像描述

在解決方案資源管理器中右鍵單擊該項目,然后找到:

  1. 共同屬性
  2. 一般
  3. 應用
  4. 啟動對象並將其設置為包含Main()方法的首選類

你聲明你的Main()方法是這樣的: main() ,這是不正確的。 它必須是Main() C#是一種區分大小寫的語言。

檢查一下: 在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM