我对C#比较陌生,现在想要用cmd编译一个名为test.cs
的基本hello world文件。它包含以下内容:
// Similar to #include<foo.h> in C++, includes system namespaces in a program
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// A name space declaration, a class is a group of namespaces
namespace Program1
{
class Hello // my class here, classes can contain multiple functions called methods which define it's behavior
{
static void Main(string[] args) // main method, just like in C/C++ it's the starting point for execution cycle
{
Console.WriteLine("Hello World");
Console.ReadKey(); // similar to _getch() in C++ waits for user to input something before closing
}
}
}
/*
* Other notes, .cs is a c# file extension
* cs files can be built via terminal by using csc foo.cs to generate foo.exe run it with foo
*/
当我尝试运行该行csc test.cs
时,我得到以下输出:
![img of issue](https://istack.dev59.com/1aS7R.webp)
"%SystemRoot%\Microsoft.NET\Framework64\v4.0.30319\csc.exe" test.cs
,而不是仅使用csc test.cs
。也就是说,将可执行文件csc
与文件扩展名一起用双引号括起来,并附上完整路径,以确保始终正常工作。路径取决于您要使用哪个.NET框架进行编译。 - Mofi