简体   繁体   English

将字符串和数字比较从VB6转换为C#

[英]Translating string and number comparison from VB6 to C#

I have to translate some code from VB6 into C#. 我必须将一些代码从VB6转换为C#。 rs is a Recordset object: rs是一个Recordset对象:

If rs.Fields("mycolumn") < 5 Then
   myarray(Val(rs.Fields("mycolumn"))) = myarray(Val(rs.Fields("mycolumn"))) + 1".
End If

The problem here is comparing the column and number, because the column is a string. 这里的问题是比较列和数字,因为列是一个字符串。 I already tried the VisualBasic Val()-method, but it doesn't behave totally the same? 我已经尝试过VisualBasic Val()方法,但是它的行为不完全一样吗?

I used this, but it doesn't give the same expression as the VB6 one. 我使用了它,但是它没有提供与VB6相同的表达。 Some of the records pass thru, when they shouldn't. 有些记录不应该通过。

if (Microsoft.VisualBasic.Conversion.Val(rs.Rows[k]["mycolumn"]) < 5)
{

}

您应该使用int.Parseint.TryParse将字符串转换为数字,然后可以进行比较:

if(int.Parse(rs.Rows[k]["mycolumn"]) < 5) { ... }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM