-1

hi guys i got problem on both of my userID.GetUserByID and getIP.GetIPAddress it tells me that i Cannot convert from 'method group' to 'string'

but if i don't add even one of them i don't get an error but i add either one of the that error pops up. down below is my code on form, dal and for my ip

sBarcodeValidation = new ValidateBarCode3Repository().ValidateBarCode3(
          sBarCode, 
          userID.getUserByID,
          getIP.GetIPAddress,
          modGlobal.gBoothID = Settings.Default.BoothID);

here is my code for getUserByID

public class GetUserByID
{
    CACHE CacheConnection = new CACHE();
    public string getUserByID(GetAllUsers getUserByID) 
    {
        try
        {
            CacheConnection.ClearParameters();
            CacheConnection.AddParameter(getUserByID.ID);
            return CacheConnection.ExecuteQuery("AGSP.Users", "GetUserByID", CommandType.StoredProcedure, InterSystems.Data.CacheTypes.ClientTypeId.tString);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
}

and here's my code for getting my ipaddress

public class GetIp
{
    //public void getHostName()
    //{
    //    string hostName = Dns.GetHostName(); // Retrive the Name of HOST  
    //    // Get the IP  
    //    string myIP = Dns.GetHostEntry(hostName).AddressList[1].ToString();
    //}
    public static IPAddress GetIPAddress()
    {
        IPAddress ip = Dns.GetHostAddresses(Dns.GetHostName()).Where(address =>
        address.AddressFamily == AddressFamily.InterNetwork).First();
        return ip;
    }
}
Mong Zhu
  • 23,309
  • 10
  • 44
  • 76

2 Answers2

2

I could tell you had some vb.net experience. In vb.net the parenthesis following a method call are provided by the editor and sometimes just assumed like in .ToString. Ok in vb but not in C#.

getIP.GetIPAddress

needs to be

getIP.GetIPAddress()

and

userID.getUserByID

needs to be

userID.getUserByID()
Mary
  • 14,926
  • 3
  • 18
  • 27
1

What the error says is that your are passing method reference instead of a string. When you type userID.getUserByID it is just a reference to that method. When you type userID.getUserByID() you are actualy invoking the method, so the result is the string returned by that method.

If I understand your code, you should just add brackets when calling methods in your ValideBarCode3() method like this

ValidateBarCode3(sBarCode, userID.getUserByID(), getIP.GetIPAddress(),modGlobal.gBoothID = Settings.Default.BoothID);
onex941
  • 145
  • 8