Is there more than one increment in the mail?

It was just an interesting thought. In languages ​​like C # and Java, I know that when it comes to incrementing and decreasing, you can do a message or a pre-increment / decrement. Like this:

int a = 5;
Console.WriteLine(a++); // Would print out 5,
                        // And then increment a to 6

Console.WriteLine(++a); // Would then print out 7 because 
                        // it increments a before printing it out

But I was wondering if there is such a thing where you can do something like this:

int a = 5;
Console.WriteLine(a += 5); // Would print out 5,
                           // And then increment a to 10

Console.WriteLine(a =+ 5); // (Or something along those lines)
                           // To print out 15 at this point

I was just interested and did not know where and how to look for an answer, so I wondered if anyone else knew anything about SO about this. Thank!

Edit: Added my question from comments

Where precisely defined a += 5and a =+5? I have never seen a second to use. Does this even exist ...? Are they the same thing?

+4
source share
5 answers

C .

 a =+ 5;
 b =- 5;

C, dmr ( ) ken

 a += 5;
 b -= 5;

, b=-5, b -= 5. "" , .

, , a++ --b, .

+4

, , #, !

static void postAdd<T>(ref T lhs, T rhs) {
    T saved = lhs;
    lhs += rhs;
    return saved;
}

Java, Java pass-by-reference ref.

+1

Console.WriteLine(a+=5);

langauge. , a WriteLine.

= + , #. # : https://msdn.microsoft.com/en-us/library/ewkkxkwb.aspx

, , IL. , Rosyln (, IronPython) .

, , , , :

public class Extensions
{
    public static int AddMul(this int x, int add, int mull)
    {
        return x * mull + add;
    }
}

:

int x = 4;
int y = x.AddMul(2, 3);  //y now equals 14
+1

, :

int a = 5;
System.out.println(a+=5);
System.out.println((a+=5)-5);
System.out.println(a);

10, 10, 15

a+=5 a . (a+=5)-5 a .

a=+5 a=5. . a=-5 (a 5).

System.out.println(+5);

5

C# :

int a = 5;
Console.WriteLine(a+=5);
Console.WriteLine((a+=5)-5);
Console.WriteLine(a);
Console.WriteLine(+5);

10, 10, 15, 5

0

. a += 5 . .

a++is a post-increment. And ++ais a preliminary increment.

0
source

All Articles