9

I want to know what is purpose of '\' in vb ? I have this statement:

frontDigitsToKeep \ 2

and I want to convert it to C#.

Please suggest.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
DotnetSparrow
  • 27,428
  • 62
  • 183
  • 316
  • See this recent question http://stackoverflow.com/questions/6013626/vb-net-vs-c-integer-division – Alex K. May 16 '11 at 14:47

4 Answers4

15

\ is the integer division operator in VB.NET.

For C#, just use the standard / operator instead and assign the result to some integer type:

frontDigitsToKeep / 2

You need an integer typecast if frontDigitsToKeep itself isn't an integer:

(int) frontDigitsToKeep / 2
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
0

The equivalent code in c# is

frontDigitsToKeep / 2

for such conversion from C# to VB.Net and vb.net to c# follow the link

http://converter.telerik.com/

0

Say you're trying to compute how many coins are packaged without caring for the leftovers. You would use \ to do integer division. So ( 4 * 5 ) \ 6 would equal 3.

As for how to put it into C#, you would use frontDigitsToKeep - (frontDigitsToKeep % 2) / 2.

Kisato
  • 11
  • 3
0

100 \ 9 = 11 in VB.NET is equivalent to 100 - (100 % 9) / 9 in C#.

frontDigitsToKeep - (frontDigitsToKeep % 2) / 2
Adi Lester
  • 24,731
  • 12
  • 95
  • 110
Saleh
  • 2,982
  • 5
  • 34
  • 59