makerofthings7
makerofthings7

Reputation: 61473

What does /= mean in C#?

I am having a tough time googling /=... can anyone tell me what this code does?

number = digits[n % digits.Length] + number;
n /= digits.Length;

My intent is to determine what the remainder of this operation is... so I know when to stop or keep going.

Upvotes: 3

Views: 7582

Answers (6)

Nathan Ryan
Nathan Ryan

Reputation: 13041

Just to add to what has already been posted in various answers, a compound assignment operator $= (replace $ with a binary operator) is similar to an assignment with the binary operator used in the right-hand side. The difference is that the left-hand side is evaluated only once. So:

x $= y

x is evaluated only once.

x = x $ y

x is evaluated twice.

Unlikely to make a difference in practice.

Upvotes: 4

Nicholas Carey
Nicholas Carey

Reputation: 74345

/= is a division operator.

x /= y ;

is the same thing as saying:

x = x / y ;

Upvotes: 0

brendan
brendan

Reputation: 29996

Per MSDN, these two are equivalent:

 n /= digits.Length;

and

 n = n/digits.Length;

Similar to the more commonly seen:

n+=1;

Upvotes: 0

Will A
Will A

Reputation: 25008

x /= y means set x equal to (in this case the integral part of) 'x divided by y'. / is the division operator.

Upvotes: 1

YetAnotherUser
YetAnotherUser

Reputation: 9356

This is the division assignment operator operator meaning n = n/digits.Length

See MSDN: /= Operator (C# Reference) for details.

Upvotes: 5

Aykut Çevik
Aykut Çevik

Reputation: 2088

Same as

n += 4; // adds 4
n *= 4; // 4 times

just division.

Upvotes: 0

Related Questions