// Namespace Declaration
using System;
// Program start class
class WelcomeCSS {
// Main begins program execution.
public static void Main() {
// Write to console
Console.WriteLine("Welcome to the C# Station Tutorial!");
}
}
"Console" 是"System" 名稱空間中的類。"WriteLine(...)"是"Console" 類中的方法。我們使用"."這個句點操作符來標記程式中的從屬元素。注意到,我們也可以這樣來書寫:"System.Console.WriteLine(...)",這樣的書寫格式是很有趣的,它是根據"namespace.class.method" 的格式進行書寫的。如果在程式的一開始,沒有採用"using System"的聲明,那麼就必須嚴格遵守"System.Console.WriteLine(...)"這樣的書寫格式。該語句的執行結果是在控制台控制台上輸出字串"Welcome to the C# Station Tutorial!" 。
// Namespace Declaration
using System;
// Program start class
class NamedWelcome {
// Main begins program execution.
public static void Main(string[] args) {
// Write to console
Console.WriteLine("Hello, {0}!", args[0]);
Console.WriteLine("Welcome to the C# Station Tutorial!");
}
}
// Namespace Declaration
using System;
// Program start class
class NamedWelcome {
// Main begins program execution.
public static void Main() {
// Write to console/get input
Console.Write("What is your name?: ");
Console.Write("Hello, {0}! ", Console.ReadLine());
Console.WriteLine("Welcome to the C# Station Tutorial!");
}
}