關鍵字是對編譯器具有特殊意義的預定義保留標識符。 它們不能在程式中用作標識符,除非它們有一個 @ 首碼。 例如,@if 是有效標識符,但 if 不是,因為 if 是關鍵字。
本主題中的第一個表列出的關鍵字在 C# 程式的任何部分都是保留標識符。 本主題中的第二個表列出了 C# 中的內容關鍵字。 內容關鍵字僅在受限制的程式上下文中具有特殊含義,並且可在該上下文外部用作標識符。 通常,在將新關鍵字添加到 C# 語言的同時,也會將它們添加為內容關鍵字,以便避免破壞用該語言的早期版本編寫的程式。
abstract |
as |
base |
bool |
break |
byte |
case |
catch |
char |
checked |
class |
const |
continue |
decimal |
default |
委託 |
do |
double |
else |
enum |
event |
explicit |
extern |
false |
finally |
fixed |
float |
for |
foreach |
goto |
if |
implicit |
in |
in(泛型修飾符) |
int |
interface |
internal |
為 |
lock |
long |
命名空間 |
new |
null |
object |
operator |
out |
out(泛型修飾符) |
override |
params |
private |
protected |
public |
readonly |
ref |
return |
sbyte |
sealed |
short |
sizeof |
stackalloc |
static |
string |
結構 |
switch |
this |
throw |
true |
try |
typeof |
uint |
ulong |
unchecked |
unsafe |
ushort |
using |
virtual |
void |
volatile |
while |
|
內容關鍵字
內容關鍵字用於提供代碼中的特定含義,但它不是 C# 中的保留字。 某些內容關鍵字(如 partial 和 where)在兩個或更多個上下文中具有特殊含義。
添加 |
別名 |
ascending |
descending |
dynamic |
from |
get |
global |
group |
into |
join |
let |
orderby |
partial(類型) |
partial(方法) |
remove |
select |
set |
value |
var |
where(泛型型別約束) |
where(查詢子句) |
yield |
|
請參見
轉自MSDN 原文http://msdn.microsoft.com/zh-cn/library/x53a06bb.aspx