關鍵字是保留字,在程式程式碼中不能將其用作變數名稱,常數名稱等。
在 C# 關鍵字不能用作識別符號。但是,如果要使用關鍵字作為識別符號,我們可以使用@
字元加到關鍵字的前面,如:@class
, @private
等。
C# 程式設計語言中可用的保留關鍵字如下列表:
abstract | base | as | bool | break | catch | case |
---|---|---|---|---|---|---|
byte | char | checked | class | const | continue | decimal |
private | protected | public | return | readonly | ref | sbyte |
explicit | extern | false | finally | fixed | float | for |
foreach | goto | if | implicit | in | in (generic modifier) | int |
ulong | ushort | unchecked | using | unsafe | virtual | void |
null | object | operator | out | out (generic modifier) | override | params |
default | delegate | do | double | else | enum | event |
sealed | short | sizeof | stackalloc | static | string | struct |
switch | this | throw | true | try | typeof | uint |
abstract | base | as | bool | break | catch | case |
volatile | while | - | - | - | - | - |