定义
C#保留字 是C#语言对于编译器有特殊意义的预定义标识,不允许用户将其作为自定义标识来使用。
用户可在保留字前添加前缀符号@ 与保留字共同使用将其转变为自定义标识来使用。例如:@new
数量
截至2015-12-28,官方认可保留字为104个,详见 MSDN - C# Keywords。其中如下保留字存在重复:
- in
- out
- partial
- where
作用域分类
以作用范围论,可分为两类:
1. 语言级保留字(含79个保留字): 在整个C#语言中都作为保留字使用。
| *语言级保留字(79) |
|---|
| 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 modifier) | int | interface | internal | is | lock | long |
| namespace | new | null | object | operator | out | out (generic modifier) | override | params | 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 |
2. 上下文保留字(含25个保留字): 在特定的上下文中作为关键字使用;除此特定的上下文外,可被允许作为自定义标识符使用。
| *上下文保留字(25) |
|---|
| add | alias | ascending | async | await | descending | dynamic | from | get | global |
|---|---|---|---|---|---|---|---|---|---|
| group | into | join | let | orderby | partial (type) | partial (method) | remove | select | set |
| value | var | where (generic type constraint) | where (query clause) | yield |
C#保留字详解
840

被折叠的 条评论
为什么被折叠?



