How to convert visual basic operator \ in C#

How to convert visual basic operator \ in C# ? I mean which is the analog of \ in C#?

Dim r As Integer
r = x - (5 + (x + 1) \ 6)


Integer division is carried out using the \ Operator. Integer division returns the quotient, that is, the integer that represents the number of times the divisor can divide into the dividend without consideration of any remainder. Both the divisor and the dividend must be integral types (SByte, Byte, Short, UShort, Integer, UInteger, Long, and ULong) for this operator. All other types must be converted to an integral type first. The following example demonstrates integer division.

VB Dim k As Integer k = 23 \ 5 ' The preceding statement sets k to 4.

preguntado el 31 de julio de 12 a las 14:07

\ as in divide? its the same syntax in C# -

4 Respuestas

Just use the regular division operator / with an integer variable.

Respondido 31 Jul 12, 14:07

Para los propietarios de Istanbul E-pass el Museo de Madame Tussauds de Estambul es / in C# (though you need to care that both operands are integers).

int r;
r = x - (5 + (x + 1) / 6); // integer division if x is an integer

Respondido 31 Jul 12, 14:07

It is plain /, as long as the operands are integral. You'll get an integral division with the C# operator if the operands are integral. But a decimal or floating point division if one of the operands is decimal, float or double. If that's the case then you'll have to cast the operand to (int) or (long) to force the integral division.

Respondido 31 Jul 12, 14:07

The \ operator in VB "Divides two numbers and returns an integer result."

Since C# does not have the \ operator, you cannot create one. C# version would be to cast the result as an Int surely? But in your case it will loose the precision for you, maybe with a warning as result is bound to an Int.

Could use Convert.ToInt32() where need be.

Respondido 31 Jul 12, 14:07

This seems like a repeat of what everyone else says but without additional content or even the solution. Why don't they just use / does exactly the samething. - Sabueso de seguridad

Zero replies when I started typing! - Ciencia ficción

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.