Click here to Skip to main content
15,900,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

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

and it is my C# code after conversion

public bool Check_GroupMembership(int GroupID)
       bool result = false;

       if (string.IsNullOrEmpty(Session["user_groups"]))

       if (!string.IsNullOrEmpty(Session["user_groups"]))
           if (String.InStr(Session["user_groups"], "~" + GroupID + "~") != 0)
               result = true;

After coversion the above VB code to C# using online conversion tool following error occur:

The best overloaded method match for 'string.IsNullOrEmpty(String)' has some invalid argument.
Anyone please help me to fix it
Maciej Los 26-May-15 2:08am    
Stop doing it! Try to understand what code does and write it in your way.
Sergey Alexandrovich Kryukov 26-May-15 2:48am    
It's incredible that I had to answer the same question today two more times!
This time, I credited your advice "Stop doing it" in two places, in respond to the today's questions by this inquirer.
Maciej Los 26-May-15 2:56am    
You're right, Sergey. I would say it's even worse, because inquirer don't want to listen good advices... ;(
Sergey Alexandrovich Kryukov 26-May-15 2:58am    

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.

Share this answer
Maciej Los 26-May-15 2:59am    
Sergey Alexandrovich Kryukov 26-May-15 3:31am    
Thank you, Maciej.
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
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900