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

Am here doing VB to C# conversion of some code but face some error listed below

Below is my VB Code

XML
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

C#
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;
       }


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
Posted
Comments
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.
—SA
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    
Apparently...

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
 
Share this answer
 
v2
Comments
Maciej Los 26-May-15 2:59am    
5ed!
Sergey Alexandrovich Kryukov 26-May-15 3:31am    
Thank you, Maciej.
—SA
A simple hack/workaround is :
C#
if("" + Session["user_groups"] != "")  // if the session value is null then appended to an empty string is an empty string
{
    Reset_Session_Data(Page);
}
 
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