Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 637
makerofthings7 Avatar asked Mar 03 '26 05:03

makerofthings7


2 Answers

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

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

like image 87
YetAnotherUser Avatar answered Mar 04 '26 17:03

YetAnotherUser


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.

like image 45
Nathan Ryan Avatar answered Mar 04 '26 17:03

Nathan Ryan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!