C#中76个关键字

本文详细介绍了C#中的76个关键字及其用法,并解释了5个在特定情况下才作为关键字的标识符。此外还提到了如何通过在关键字前加@来作为变量名使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

C#中76个关键字:

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 int interface

internal is lock long namespace

new null object operator out

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

while

5个在某些情况下是关键字:

get set value add remove 


C#中有76个在任何情况下都有固定意思的关键字。另外还有5个在特定情况下才有固定意思的标识符。例如,value能用来作为变量名,但有一种情况例外,那就是它用作属性/索引器的set语句的时候是一关键字。

但你可以在关键字前加@来使它可以用作变量名:

int @int = 42;

不过在一般情况下不要使用这种变量名。

你也可以使用@来产生跨越几行的字符串,这对于产生正则表达式非常有用。例如:

string pattern = @"

( # start the group

abra(cad)? # match abra and optional cad

)+"; # one or more occurrences

如果你要在字符串中包含双引号,那你可以这样:

string quote = @"""quote""&q
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值