不一样的入门:看C# Hello World的17种写法
http://developer.51cto.com/art/200908/145356.htm
C# Hello World写法入门:
1. 初学者
public class HelloWorld
{
public static void Main()
{
System.Console.WriteLine("HELLO WORLD");
}
}
2. 改进的HELLO WORLD
using System;
public class HelloWorld
{
public static void Main()
{
Console.WriteLine("HELLO WORLD");
}
}
3. 命令行形式
using System;
public class HelloWorld
{
public static void Main(string[] args)
{
Console.WriteLine(args[0]);
}
}
4. 构造函数
using System;
public class HelloWorld
{
public HelloWorld()
{
Console.WriteLine("HELLO WORLD");
}
public static void Main()
{
HelloWorld hw = new HelloWorld();
}
}
C# Hello World写法进阶:
5. 面向对象
using System;
public class HelloWorld
{
public void helloWorld()
{
Console.WriteLine("HELLO WORLD");
}
public static void Main()
{
HelloWorld hw = new HelloWorld();
hw.HelloWorld();
}
}
6. 从其他类
using System;
public class HelloWorld
{
public static void Main()
{
HelloWorldHelperClass hwh = new HelloWorldHelperClass();
hwh.writeHelloWorld();
}
}
public class HelloWorldHelperClass
{
public void writeHelloWorld()
{
Console.WriteLine("Hello World");
}
}
7. 继承
abstract class HelloWorldBase
{
public abstract void writeHelloWorld();
}
class HelloWorld : HelloW