Take the 2-minute tour ×

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.

share|improve this question
Uhm.. It is the same? –  Gerald Versluis Jul 31 '12 at 13:08
\ as in divide? its the same syntax in C# –  Gerard Sexton Jul 31 '12 at 13:08
developerfusion.com/tools/convert/vb-to-csharp. Works perfectly. –  mellamokb Jul 31 '12 at 13:09

4 Answers 4

up vote 9 down vote accepted

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

share|improve this answer

It is / 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
share|improve this answer

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.

share|improve this answer

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.

share|improve this answer
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. –  Ramhound Jul 31 '12 at 13:34
Zero replies when I started typing! –  Science_Fiction Jul 31 '12 at 13:37

Your Answer


