如何調用靜態方法?我想從我創建的課程中調用此函數,我想從IP獲取位置。我已經聲明它,但我需要做的是調用的方法......作爲static
......在C中調用靜態方法#
爲了跟你說實話,我很困惑在這裏,我需要實例address
,city
等。?
我已經完成了這項工作;
LocationTools.cs
public static class LocationTools
{
public static void GetLocationFromIP(string address, out string city, out string region, out string country, out double? latitude, out double? longitude)
{
Home.cs
public string IPAPIKey
{
get
{
return WebConfigurationManager.AppSettings["IPAPIKey"];
}
}
////To get the ip address of the machine and not the proxy use the following code
static void GetLocationFromIP()
{
string strIPAddress = Request.UserHostAddress.ToString();
strIPAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (strIPAddress == null || strIPAddress == "")
{
strIPAddress = Request.ServerVariables["REMOTE_ADDR"].ToString();
}
}
}
}
你試過了什麼?只需使用LocationTools.GetLocationFromIP(...); –