从vb到c#的代码转换 [英] code conversoin from vb to c#
问题描述
你好,
将一行代码c#转换为VB时出现错误
代码是
在vb:CType(MyUserControl.FindControl("txtid"),TextBox).Text =(CType(Val(mo.maxrows(从provider_master中选择max(supplier_id)max))),整数)+ 1)
转换后,代码变为((TextBox)MyUserControl.FindControl("txtid")).Text =(Convert.ToInt32( Conversion .Val(mo.maxrows( 从Supplier_master中选择max(supplier_id)")))+ 1);
但问题是我在转换"附近遇到错误.指出Conversion不在当前上下文中.
Hello,
I am getting An error while converting a line of code c# to VB
the code is
in vb:CType(MyUserControl.FindControl("txtid"), TextBox).Text = (CType(Val(mo.maxrows("select max(supplier_id) from supplier_master")), Integer) + 1)
after conversion the code become like this ((TextBox)MyUserControl.FindControl("txtid")).Text = (Convert.ToInt32(Conversion.Val(mo.maxrows("select max(supplier_id) from supplier_master"))) + 1);
but the problem is that i am getting a error near Conversion. sating that Conversion is not in the current context.
will any one help me about this.
推荐答案
AFAIK,在C#中没有类似于Conversion的关键字.
您不需要执行任何其他操作(因为您已经使用过Convert.ToInt
).
您也可以尝试使用Int32.TryParse
[
AFAIK, there is no keyword like Conversion in C#.
You don''t need to do anything else (since you''ve already usedConvert.ToInt
).
You can also try usingInt32.TryParse
[^].
翻译不正确.必须是VisualBasic
,Microsoft.VisualBasic.Conversion
中的Conversion
:
http://msdn.microsoft.com/zh-我们/library/microsoft.visualbasic.conversion%28v=vs.100%29.aspx [Parse或TryParse
方法:
http://msdn.microsoft.com/en-us/library/system.int32. parse.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/f02979c7.aspx [ ^ ].
—SA
Bad translation. This must beConversion
fromVisualBasic
,Microsoft.VisualBasic.Conversion
:
http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.conversion%28v=vs.100%29.aspx[^].
You can always reference this assembly (Microsoft.VisualBasic.dll) and use it in C# project. But this is not a good thing, using a non-standard proprietary library. This must be "conversion" from string. The word "conversion" is pretty silly here, this is "parsing". A standard way of parsing from string is theParse
orTryParse
methods:
http://msdn.microsoft.com/en-us/library/system.int32.parse.aspx[^],
http://msdn.microsoft.com/en-us/library/f02979c7.aspx[^].
—SA
这篇关于从vb到c#的代码转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!