You... didn't implement the method. You have this:
private static string stringGetPublicIpAddress()
{
throw new NotImplementedException();
}
So of course any time you call that method, it's going to throw that exception. It looks like you did implement the method you want here, though:
private string GetPublicIpAddress()
{
// the rest of your code
}
Maybe this is the result of some copy/paste error? Try getting rid of the small method that throws the exception and changing the implemented method to be static:
private static string GetPublicIpAddress()
{
// the rest of your code
}
Then update anywhere you call it from this:
stringGetPublicIpAddress();
to this:
GetPublicIpAddress();
This really just looks like copy/paste errors gone wrong in strange ways. Or perhaps you're struggling with the difference between static and instance methods? Maybe you implemented the method, but the compiler suggested that you needed a static method? There's a lot to read about static vs. instance methods/members which I won't really get into here. It's a significant concept in object-oriented programming.
In this particular case, since you're in the context of a static method in Main
, anything you call from Main
on that class (the Program
class) also needs to be static, unless you create an instance of Program
like this:
var program = new Program();
This would allow you to call instance methods on Program
:
program.SomeNonStaticMethod();
But for a small application such as this, that isn't really necessary.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…