C#(英文:C Sharp)係微軟跟 .NET Framework 標準設計出嚟嘅一隻高階程式語言,喺 2000 年發行。C# 由 C 程式語言同 C++ 衍生出嚟,同 Java 程式語言亦有唔少相似之處。C# 用途廣泛,支援多種編程範式,尤其係物件導向編程,而且仲同多種遊戲引擎相容,喺廿一世紀初係編寫遊戲程式嘅一種常用語言。
編程範式 | 結構化、物件導向、泛型 |
---|---|
家族 | C |
設計者 | 微軟 |
編程員 | 微軟 |
第一次出現 | 2000年 |
穩定版本 | 10 / 2021年11月8號 |
操作系統 | Windows、Linux、Mac OS X、Android |
軟件授權 |
|
副檔名 | .cs , .csx |
網站 | C# Language |
Major implementations | |
.NET Core、.NET Framework、Mono、DotGNU | |
Dialects | |
Cω、Spec#、Polyphonic C# | |
啟發語言 | |
C++、Java、Eiffel、Modula-3、Object Pascal | |
影響語言 | |
Clojure、 D語言、F#、Java 5、Nemerle、Vala |
一個用 C♯ 寫嘅 Hello World 程式如下:
using System; // 會用到 System 入面嗰柞指令; class Hello // class 可以包括 method(子程序) { static void Main() // Main 表示主程序,void 表示個程序唔會俾乜嘢 output; { Console.WriteLine("Hello, World"); // 喺 Console 出「Hello, World」嘅字樣; } }
一個 C# 程式基本結構如下:
using System; namespace YourNamespace { class YourClass { } struct YourStruct { } interface IYourInterface { } delegate int YourDelegate(); enum YourEnum { } namespace YourNestedNamespace { struct YourStruct { } } class YourMainClass { static void Main(string[] args) { // 主程式喺呢度... } } }
一個 C# 程式另一個可能嘅結構如下,呢種結構常用於遊戲引擎嘅 C# 手稿(簡單講用嚟黐落去啲遊戲物件嘅程式):
using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { // 初始化 void Start() { // 個程式喺一開始嗰陣會行一次 Start 嘅碼。 } void Update() { // 個程式喺開始後每個時間會行一次 Update 嘅碼。 } }
C# 支援好多種資料類型。C# 程式入面啲變數可以屬多種嘅資料類型,包括咗:
... 等等。
C#容許多種控制流程功能,包括:
if
for
while
Do {...} while
foreach([datatype] name1 in array1)
switch([condition variable]) {case [value]:... default:}
invoke
... 等等。
ToString()
System.Console.WriteLine("")
System.Console.ReadLine("")
This article uses material from the Wikipedia 粵語 article C♯, which is released under the Creative Commons Attribution-ShareAlike 3.0 license ("CC BY-SA 3.0"); additional terms may apply (view authors). 呢度嘅所有文字係根據 CC BY-SA 4.0 牌照嘅條款發佈;可能會有附加嘅條款。 Images, videos and audio are available under their respective licenses.
®Wikipedia is a registered trademark of the Wiki Foundation, Inc. Wiki 粵語 (DUHOCTRUNGQUOC.VN) is an independent company and has no affiliation with Wiki Foundation.