无法从“方法组”转换为“字符串”

时间:2018-07-03 05:42:44

标签: c# intersystems-cache

嗨,我的userID.GetUserByIDgetIP.GetIPAddress都遇到了问题 它告诉我我无法从“方法组”转换为“字符串”

但是如果我什至不添加其中一个,我不会收到错误,但我会弹出该错误之一。下面是我在表单,dal和我的ip上的代码

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

这是我的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;
        }
    }
}

这是获取我的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;
    }
}

2 个答案:

答案 0 :(得分:1)

我可以告诉您有一些vb.net经验。在vb.net中,方法调用后的括号由编辑器提供,有时就像.ToString中一样假定。在vb中可以,但在C#中不能。

getIP.GetIPAddress

需要成为

getIP.GetIPAddress()

userID.getUserByID

需要成为

userID.getUserByID()

答案 1 :(得分:1)

错误说明您正在传递方法引用而不是字符串。当您输入userID.getUserByID时,它只是对该方法的引用。键入userID.getUserByID()时,实际上是在调用该方法,因此结果是该方法返回的字符串。

如果我了解您的代码,则应在调用ValideBarCode3()方法中的方法时添加方括号,例如

ValidateBarCode3(sBarCode, userID.getUserByID(), getIP.GetIPAddress(),modGlobal.gBoothID = Settings.Default.BoothID);
相关问题