前,后递增/递减运算符在C# [英] Pre and post increment/decrement operators in C#

查看:519
本文介绍了前,后递增/递减运算符在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,没有任何人知道为什么下面将编译:

In C#, does anybody know why the following will compile:

int i = 1;
++i;
i++;



但这不会编译?

but this will not compile?

int i = 1;
++i++;



(编译器错误:一个递增或递减运算的操作数必须是变量,属性或索引。 )

(Compiler error: The operand of an increment or decrement operator must be a variable, property or indexer.)

推荐答案

在正在运行的其他结果的其中一个操作数,一个递增/递减的结果是一个值 - 你不能在它必须是可设置一个变量的值使用递增/递减

you are running one of the operands on the result of the other, the result of a increment/decrement is a value - and you can not use increment/decrement on a value it has to be a variable that can be set.

这篇关于前,后递增/递减运算符在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆