C# 关键字
关键字是对编译器具有特殊意义的预定义保留标识符。它们不能在程序中用作标识符,除非它们有一个 @ 前缀。例如,@if 是有效的标识符,但 if 不是,因为 if 是关键字。
本主题中的第一个表列出的关键字在 C# 程序的任何部分都是保留标识符。本主题中的第二个表列出了 C# 中的上下文关键字。上下文关键字仅在受限制的程序上下文中具有特殊含义,并且可在该上下文外部用作标识符。通常,在将新关键字添加到 C# 语言的同时,也会将它们添加为上下文关键字,以便避免破坏用该语言的早期版本编写的程序。
abstract |
event |
new |
struct |
as |
explicit |
null |
switch |
base |
extern |
object |
this |
bool |
false |
operator |
throw |
break |
finally |
out |
true |
byte |
fixed |
override |
try |
case |
float |
params |
typeof |
catch |
for |
private |
uint |
char |
foreach |
protected |
ulong |
checked |
goto |
public |
unchecked |
class |
if |
readonly |
unsafe |
const |
implicit |
ref |
ushort |
continue |
in |
return |
using |
decimal |
int |
sbyte |
virtual |
default |
interface |
sealed |
volatile |
delegate |
internal |
short |
void |
do |
is |
sizeof |
while |
double |
lock |
stackalloc |
|
else |
long |
static |
|
enum |
namespace |
string |
|
上下文关键字
上下文关键字用于提供代码中的特定含义,但它不是 C# 中的保留字。某些上下文关键字(如 partial 和 where)在两个或更多个上下文中具有特殊含义。
from |
get |
group |
into |
join |
let |
orderby |
partial(类型) |
partial(方法) |
select |
set |
value |
var |
where(泛型类型约束) |
where(查询子句) |
yield |