VB转换为C#代码错误 [英] VB Conversion to C# code error
本文介绍了VB转换为C#代码错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
我在这里做VB到C#转换的一些代码,但是面对下面列出的一些错误
以下是我的VB代码
Hello
Am here doing VB to C# conversion of some code but face some error listed below
Below is my VB Code
Public Overloads Function Check_GroupMembership(ByVal GroupID As Integer) As Boolean
Dim result As Boolean = False
If Session("user_groups") = "" Then Reset_Session_Data(Page)
If Session("user_groups") <> "" Then
If InStr(Session("user_groups"), "~" & GroupID & "~") <> 0 Then result = True
End If
Return result
End Function
转换后是我的C#代码
and it is my C# code after conversion
public bool Check_GroupMembership(int GroupID)
{
bool result = false;
if (string.IsNullOrEmpty(Session["user_groups"]))
Reset_Session_Data(Page);
if (!string.IsNullOrEmpty(Session["user_groups"]))
{
if (String.InStr(Session["user_groups"], "~" + GroupID + "~") != 0)
result = true;
}
使用在线转换工具将上述VB代码转换为C#后发生以下错误:
string.IsNullOrEmpty(Session [user_groups]):
'string.IsNullOrEmpty(String)'的最佳重载方法匹配有一些无效的参数。
任何人都可以帮我解决一下
After coversion the above VB code to C# using online conversion tool following error occur:
string.IsNullOrEmpty(Session["user_groups"]):
The best overloaded method match for 'string.IsNullOrEmpty(String)' has some invalid argument.
Anyone please help me to fix it
推荐答案
你总是可以自动翻译代码(不是转换!)。请看我过去的答案:
代码解释,C#到VB.NET [ ^ ]。
最可靠,最优质的方法是使用开源的ILSpy。
Maciej Los在对这个问题的评论中得到了很好的建议:停止这样做!请遵循这个建议。
-SA
You can always translate code (not "convert"!) automatically. Please see my past answer:
Code Interpretation, C# to VB.NET[^].
Most reliable and quality method is using open-source ILSpy.
You got a very good advice by Maciej Los in his comment to the question: stop doing it! Do follow this advice.
—SA
一个简单的黑客/解决方法是:
A simple hack/workaround is :
if("" + Session["user_groups"] != "") // if the session value is null then appended to an empty string is an empty string
{
Reset_Session_Data(Page);
}
这篇关于VB转换为C#代码错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文