关键字是 C# 编译器预定义的保留字。这些关键字不能用作标识符,但是,如果您想使用这些关键字作为标识符,可以在关键字前面加上 @ 字符作为前缀。
在 C# 中,有些标识符在代码的上下文中有特殊的意义,如 get 和 set,这些被称为上下文关键字(contextual keywords)。
下表列出了 C# 中的保留关键字(Reserved Keywords)和上下文关键字(Contextual Keywords):
保留关键字 |
||||||
abstract |
as |
base |
bool |
break |
byte |
case |
catch |
char |
checked |
class |
const |
continue |
decimal |
default |
delegate |
do |
double |
else |
enum |
event |
explicit |
extern |
FALSE |
finally |
fixed |
float |
for |
foreach |
goto |
if |
implicit |
in |
in (generic |
int |
modifier) |
||||||
interface |
internal |
is |
lock |
long |
namespace |
new |
null |
object |
operator |
out |
out |
override |
params |
(generic |
||||||
modifier) |
||||||
private |
protected |
public |
readonly |
ref |
return |
sbyte |
sealed |
short |
sizeof |
stackalloc |
static |
string |
struct |
switch |
this |
throw |
TRUE |
try |
typeof |
uint |
ulong |
unchecked |
unsafe |
ushort |
using |
virtual |
void |
volatile |
while |
|||||
上下文关键字 |
||||||
add |
alias |
ascending |
descending |
dynamic |
from |
get |
global |
group |
into |
join |
let |
orderby |
partial |
(type) |
||||||
partial |
remove |
select |
set |
|||
(method) |