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.

abstractabstract asas basebase boolbool
breakbreak bytebyte casecase catchcatch
charchar checkedchecked classclass constconst
continuecontinue decimaldecimal defaultdefault delegatedelegate
dodo doubledouble elseelse enumenum
eventevent explicitexplicit externextern falsefalse
finallyfinally fixedfixed floatfloat forfor
foreachforeach gotogoto ifif implicitimplicit
inin intint interfaceinterface internalinternal
isis locklock longlong namespacenamespace
newnew nullnull objectobject operatoroperator
outout overrideoverride paramsparams privateprivate
protectedprotected publicpublic readonlyreadonly refref
returnreturn sbytesbyte sealedsealed shortshort
sizeofsizeof stackallocstackalloc staticstatic stringstring
structstruct switchswitch thisthis throwthrow
truetrue trytry typeoftypeof uintuint
ulongulong uncheckedunchecked unsafeunsafe ushortushort
usingusing using staticusing static virtualvirtual voidvoid
volatilevolatile whilewhile

內容關鍵字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.

addadd aliasalias ascendingascending
asyncasync awaitawait byby
descendingdescending dynamicdynamic equalsequals
fromfrom getget globalglobal
groupgroup intointo joinjoin
letlet nameofnameof onon
orderbyorderby partial (型別)partial (type) partial (方法)partial (method)
removeremove selectselect setset
非受控(泛型型別條件約束)unmanaged (generic type constraint) value varvar
when (篩選條件)when (filter condition) where (泛型型別條件約束)where (generic type constraint) where (查詢子句)where (query clause)

請參閱See also