3

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.

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
makerofthings7
  • 60,103
  • 53
  • 215
  • 448

6 Answers6

5

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

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

YetAnotherUser
  • 9,156
  • 3
  • 39
  • 53
4

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.

Nathan Ryan
  • 12,893
  • 4
  • 26
  • 37
  • If you say: `DoHeavyWorkCauseSideEffectsAndReturnObject().MyIntProperty /= 100;`, then it might make a difference compared to `DoHeavyWorkCauseSideEffectsAndReturnObject().MyIntProperty = DoHeavyWorkCauseSideEffectsAndReturnObject().MyIntProperty / 100;`. But most of the time you split it into two statements, and so you're right, there's no practical difference. – Jeppe Stig Nielsen Nov 10 '12 at 13:32
1

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

Will A
  • 24,780
  • 5
  • 50
  • 61
0

Same as

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

just division.

Aykut Çevik
  • 2,060
  • 3
  • 20
  • 27
0

Per MSDN, these two are equivalent:

 n /= digits.Length;

and

 n = n/digits.Length;

Similar to the more commonly seen:

n+=1;
brendan
  • 29,308
  • 20
  • 68
  • 109
0

/= is a division operator.

x /= y ;

is the same thing as saying:

x = x / y ;
Nicholas Carey
  • 71,308
  • 16
  • 93
  • 135