开发者

\ operator in VB [duplicate]

开发者 https://www.devze.com 2023-03-06 18:13 出处:网络
This question already has answers here: How to convert visual basic operator \\ in C# (4 answers) Closed 7 years ago.开发者_JAVA百科
This question already has answers here: How to convert visual basic operator \ in C# (4 answers) Closed 7 years ago.开发者_JAVA百科

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.


\ 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


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

frontDigitsToKeep - (frontDigitsToKeep % 2) / 2


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/


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消