关键字是保留字,在程序代码中不能将其用作变量名称,常量名称等。
在 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 | - | - | - | - | - |