C# 關鍵字C# Keywords

關鍵字是預先定義的保留識別項,它對編譯器具有特殊意義。Keywords are predefined, reserved identifiers that have special meanings to the compiler. 您必須在關鍵字加上 @ 做為前置詞,才能將它們當做程式中的識別項使用。They cannot be used as identifiers in your program unless they include @ as a prefix. 例如,@if 是有效的識別項,但 if 不是,因為 if 是關鍵字。For example, @if is a valid identifier, but if is not because if is a keyword.

本主題中的第一個表格列出在 C# 程式的任何部分中為保留識別項的關鍵字。The first table in this topic lists keywords that are reserved identifiers in any part of a C# program. 本主題中的第二個表格列出 C# 中的內容關鍵字。The second table in this topic lists the contextual keywords in C#. 內容關鍵字只在有限的程式內容中具有特殊意義,並且可在該內容以外的地方用來當做識別項。Contextual keywords have special meaning only in a limited program context and can be used as identifiers outside that context. 一般而言,將新的關鍵字加入至 C# 語言時,會以內容關鍵字加入它們,以避免中斷利用舊版本撰寫的程式。Generally, as new keywords are added to the C# language, they are added as contextual keywords in order to avoid breaking programs written in earlier versions.

抽象abstract 作為as basebase boolbool
breakbreak bytebyte 情況 下case catchcatch
charchar 檢查checked classclass constconst
繼續continue decimaldecimal 預設default 委託delegate
dodo doubledouble elseelse 列舉enum
eventevent 明確explicit externextern falsefalse
最後finally 固定fixed floatfloat forfor
Foreachforeach gotogoto ifif 隱式implicit
inin intint 介面interface internalinternal
isis 鎖定lock longlong 網路中namespace
新增功能new nullnull 物件object 算子operator
out overrideoverride paramsparams privateprivate
protectedprotected publicpublic 唯讀readonly refref
returnreturn sbytesbyte sealedsealed shortshort
sizeofsizeof stackallocstackalloc staticstatic stringstring
structstruct switchswitch thisthis throwthrow
truetrue 嘗試try 類型typeof uintuint
ulongulong uncheckedunchecked 安全unsafe ushortushort
使用using virtualvirtual voidvoid volatilevolatile

內容關鍵字Contextual keywords

內容關鍵字可用來在程式碼中提供特定的意義,但它不是 C# 中的保留字。A contextual keyword is used to provide a specific meaning in the code, but it is not a reserved word in C#. 某些內容關鍵字 (例如 partialwhere) 在兩個以上的內容中具有特殊意義。Some contextual keywords, such as partial and where, have special meanings in two or more contexts.

新增add 別名alias ascendingascending
asyncasync 等待await byby
descendingdescending 動態dynamic equalsequals
fromfrom getget 全球global
群組group intointo 加入join
let nameofnameof on
順序orderby 部份(類型)partial (type) 部分(方法)partial (method)
移除remove 選擇select 設定set
非託管 (泛型類型約束)unmanaged (generic type constraint) valuevalue varvar
when (篩選條件)when (filter condition) where (泛型型別條件約束)where (generic type constraint) where (查詢子句)where (query clause)

另請參閱See also