Calling a Static method in C#

前端 未结 5 1518
[愿得一人]
[愿得一人] 2021-02-19 11:46

How do I call a static method? I want to call this from a class I have created, I want to get the location from IP. I\'ve declared it but what I need to do is call the method...

5条回答
  •  误落风尘
    2021-02-19 12:11

    There you go

    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();
        }
    
        string city = string.Empty;
        string region = string.Empty;
        string country = string.Empty;
        double latitude = -1.00;
        double longitude = -1.00;
    
        LocationTools.GetLocationFromIP(strIPAddress, out city, out region, out country, out latitude, out longitude)
    }
    

提交回复
热议问题