c# - 为什么 VS Studio Code 中的终端使用了错误的程序?

标签 c# visual-studio-code terminal

我确信这是一个愚蠢的问题,但答案很明显,但我就是想不出来。我正在 VS Code 中练习 C#,并将所有项目放在一个文件夹中。现在,当我尝试使用“dotnet run”测试第二个程序的启动时,终端不断尝试访问第一个项目,而不是打开的项目。

“AdditionCalc.cs(7,17): 错误 CS0017: 程序定义了多个入口点。使用/main 进行编译以指定包含入口点的类型。[C:\Users\dylan\Desktop\C#练习\C# 练习.csproj]" 是我收到的错误消息。 “AdditionCalc.cs”是我的第一个项目,我在其中制作了一个简单的加法计算器。

using System;

namespace Practice
{
  class Calculator
  {
    static void Main(string[] args)
    {
 
 string str1;
 string str2;
 
 int number1;
 int number2;

 Console.WriteLine("Enter Number One");
    str1 = Console.ReadLine();
 Console.WriteLine("Enter Number Two");  
    str2 = Console.ReadLine();
    
     number1 = Int32.Parse(str1);
     number2 = Int32.Parse(str2);

      int answer = number1 + number2;
           
            Console.WriteLine("Those two numbers added up is: " + answer);

            string fivehundo = (answer >=500) ? "That number is bigger than 500" : "That number is smaller than 500";

            Console.WriteLine(fivehundo);

                
    }
  }
}

这是我的第一个项目

using System;

namespace Test {   

    class NumberGuesser {
        static void Main(string[] args){

        
        
        Random rnd = new Random();
        int number = rnd.Next(1, 11);
        
        
        Console.WriteLine(number);
        
        }
    }
} 

这是我的第二个项目,用户将猜测一个数字,每次控制台都会返回实际数字高于或低于输入的数字。

我是否必须将这些文件保存在完全独立的位置并每次创建一个新控制台?或者我必须以特定方式打开文件? 非常感谢您的帮助,我知道这可能是一个愚蠢的问题,而且我忽略了一些非常基本的东西

最佳答案

每个项目都有不同的文件夹是非常标准的,所以这是我的建议。

可能有另一种方法可以让它在一个文件夹中全部工作,但您也可以从一开始就采用典型的方法。

关于c# - 为什么 VS Studio Code 中的终端使用了错误的程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64000199/

相关文章:

c# - 如何比较两个对象数组

python - 哪一个是我真正的 python 解释器 (vsc)?

visual-studio-code - 突出显示当前选定的开始标签的结束标签

MySQL 没有 root/ super 用户

macos - -bash : matlab: command not found

c# - 将 C++ .lib 和 .h 文件导入 C# 项目?

c# - 当程序运行时发生事件时会发生什么

c# - 编译时多态/重载

react-native - Visual Studio 代码 react-native : Current workspace is not a React Native project

linux - 是否可以在 shell (zsh) 中进行实时文本替换?