What does% mean in c #?

Sorry for the possible repeated question, the symbol %does not match the search capability.

What does it mean %? I can't seem to stick to this.

Example:

rotation = value % MathHelper.TwoPi;

is a specific instance.

But I found the code that most often uses %. The "Think" module is called, but I'm not sure.

Previous Post:

With a well-designed tip

+3
source share
7 answers

This is the module operator. It returns the remainder of an integer.

int remainder = 2 % 1; // (remainder variable is assigned to 0) 
int remainder2 = 3 % 2; // (remainder variable is assigned to 1)
+3
source

% Operator (C # link)

The% operator calculates the remainder after dividing its first operand by its second. All numeric types have predefined remainder operators.

+12
source

. MSDN:

+7

. , .

  • 5% 2 = 1
  • 6% 2 = 0
  • 5% 3 = 2.
+4

# modulus,

:

int remainder = 10 % 3 //remainder is 1
+4

Let's say that

x / y = z,
x, y, z being integers.

There is no guarantee that

z * y = x, because the "/" operator rounds down.

So, we have to add the remainder to our equation:

z * y = x + r.

z * y = x + r
z * (-y) = - (z * y) = -(x + r) = -x - r

This means that the result of the operator "%" can be negative, which means that the operator "%" or the remainder is different from the absolute value of the relation, because the result is not guaranteed to be canonical.

+3
source

All Articles