C# Language Specification


Postfix increment and decrement operators



Download 0,75 Mb.
bet219/524
Sana06.01.2022
Hajmi0,75 Mb.
#324842
1   ...   215   216   217   218   219   220   221   222   ...   524
Bog'liq
CSharp Language Specification

Postfix increment and decrement operators


post-increment-expression:
primary-expression ++


post-decrement-expression:
primary-expression --

The operand of a postfix increment or decrement operation must be an expression classified as a variable, a property access, or an indexer access. The result of the operation is a value of the same type as the operand.

If the primary-expression has the compile-time type dynamic then the operator is dynamically bound (§7.2.2), the post-increment-expression or post-decrement-expression has the compile-time type dynamic and the following rules are applied at run-time using the run-time type of the primary-expression.

If the operand of a postfix increment or decrement operation is a property or indexer access, the property or indexer must have both a get and a set accessor. If this is not the case, a binding-time error occurs.

Unary operator overload resolution (§7.3.3) is applied to select a specific operator implementation. Predefined ++ and -- operators exist for the following types: sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, and any enum type. The predefined ++ operators return the value produced by adding 1 to the operand, and the predefined -- operators return the value produced by subtracting 1 from the operand. In a checked context, if the result of this addition or subtraction is outside the range of the result type and the result type is an integral type or enum type, a System.OverflowException is thrown.

The run-time processing of a postfix increment or decrement operation of the form x++ or x-- consists of the following steps:



  • If x is classified as a variable:

  • x is evaluated to produce the variable.

  • The value of x is saved.

  • The selected operator is invoked with the saved value of x as its argument.

  • The value returned by the operator is stored in the location given by the evaluation of x.

  • The saved value of x becomes the result of the operation.

  • If x is classified as a property or indexer access:

  • The instance expression (if x is not static) and the argument list (if x is an indexer access) associated with x are evaluated, and the results are used in the subsequent get and set accessor invocations.

  • The get accessor of x is invoked and the returned value is saved.

  • The selected operator is invoked with the saved value of x as its argument.

  • The set accessor of x is invoked with the value returned by the operator as its value argument.

  • The saved value of x becomes the result of the operation.

The ++ and -- operators also support prefix notation (§7.7.5). Typically, the result of x++ or x-- is the value of x before the operation, whereas the result of ++x or --x is the value of x after the operation. In either case, x itself has the same value after the operation.

An operator ++ or operator -- implementation can be invoked using either postfix or prefix notation. It is not possible to have separate operator implementations for the two notations.



      1. Download 0,75 Mb.

        Do'stlaringiz bilan baham:
1   ...   215   216   217   218   219   220   221   222   ...   524




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish