【发布时间】:2017-08-22 03:53:19
【问题描述】:
我是 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 是您环境变量的一部分吗?可能编译器不在您的桌面中(请参阅执行命令的路径)。您可能想搜索编译器的位置并从那里运行它
-
如何找到我的环境变量?我对 ubuntu 上的终端有点熟悉,但我是 cmd 的新手
-
运行
"%SystemRoot%\Microsoft.NET\Framework64\v4.0.30319\csc.exe" test.cs而不是仅仅运行csc test.cs,即带有文件扩展名的可执行文件csc并用双引号括起来的完整路径始终有效。路径取决于您要用于编译的 .NET 框架。
标签: c# cmd path environment-variables csc