helloworld我与C#的第一次相交
using System;
namespace HelloWorld
{
class HelloWorld
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Console.ReadKey();
}
}
}
程序结构
1、using System;
using 用于在程序中包含命名空间。一个程序可以包含多个 using 语句。
2、 namespace 声明命名空间。一个 namespace 里包含了一系列的类。
3、class 声明一个类。
4、 Main 声明方法。每一个 C# 程序至少有一个带有 Main 方法的类,是所有 C# 程序的入口点。
5、Console是系统里的一个System 命名空间中的 Console 类,里头WriteLine为类里的方法。类似与print().
注意:
C# 分大小写。
所有的语句和表达式必须以;结尾。
程序的执行从 Main 方法开始。
运行程序
1、在记事本里添加上面代码。保存文件为 helloworld.cs。
2、打开命令提示符工具,定位到文件所保存的目录。
3、输入 csc helloworld.cs。生成 helloworld.exe 可执行文件。
4、输入 helloworld
like this:
很有意思,快试试吧!