12.3.3.23 && expressions

本文围绕C#中形式为expr-first && expr-second的表达式展开,详细阐述了变量v在expr-first前后、expr-second前后以及整个expr前后的明确赋值状态,并通过示例说明变量i在if语句不同嵌入语句中的赋值情况。
12.3.3.23 && expressions
For an expression expr of the form expr-first && expr-second:
?The definite assignment state of v before expr-first is the same as the
definite assignment state of v
before expr.
C# LANGUAGE SPECIFICATION
110
?The definite assignment state of v before expr-second is definitely
assigned if the state of v after
expr-first is either definitely assigned or .definitely assigned after true
expression.. Otherwise, it is
not definitely assigned.
?The definite assignment state of v after expr is determined by:
o If the state of v after expr-first is definitely assigned, then the state
of v after expr is
definitely assigned.
o Otherwise, if the state of v after expr-second is definitely assigned,
and the state of v after
expr-first is .definitely assigned after false expression., then the state
of v after expr is
definitely assigned.
o Otherwise, if the state of v after expr-second is definitely assigned or
.definitely assigned
after true expression., then the state of v after expr is .definitely
assigned after true
expression..
o Otherwise, if the state of v after expr-first is .definitely assigned
after false expression., and
the state of v after expr-second is .definitely assigned after false
expression., then the state
of v after expr is .definitely assigned after false expression..
o Otherwise, the state of v after expr is not definitely assigned.
[Example: In the example
class A
{
static void F(int x, int y) {
int i;
if (x >= 0 && (i = y) >= 0) {
// i definitely assigned
}
else {
// i not definitely assigned
}
// i not definitely assigned
}
}
the variable i is considered definitely assigned in one of the embedded
statements of an if statement but not
in the other. In the if statement in method F, the variable i is definitely
assigned in the first embedded
statement because execution of the expression (i = y) always precedes
execution of this embedded
statement. In contrast, the variable i is not definitely assigned in the
second embedded statement, since
x >= 0 might have tested false, resulting in the variable i抯 being
unassigned. end example]
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值