在c#中的getip中有警告 [英] have warning in getip in c#

查看:63
本文介绍了在c#中的getip中有警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!我试试getip时会收到警告。



  public   UInt32  GetIpAdress( String  Ipadress)
{
System.Net.IPAddress ipaddress;
尝试
{
ipaddress = System.Net.IPAddress.Parse(Ipadress);
}
catch
{
MessageBox.Show( IP地址输入错误!);
return 0 ;
}
return Convert.ToUInt32(ipaddress.Address); // < span class =code-comment>警告4'System.Net.IPAddress.Address'已废弃:'此属性已被弃用。它是地址族依赖的。请使用IPAddress.Equals方法执行比较。
}



如何解决?你能帮助我吗? PLZ。 :d。

感谢您的关注:)。

解决方案

您可能必须使用 IPAddress.MapToIPv4方法 [ ^ ]而不是。

  return  Convert.ToUInt32(Ipadress.MapToIPv4()); 



作为一方注意, Ipadress 参数应命名为 ipAddress ;参数名称应该是驼峰式的。 GetIpAdress 也应命名为 GetIpAddress


Hi everybody! i have a warning when try getip.

public UInt32 GetIpAdress(String Ipadress)
  {
      System.Net.IPAddress ipaddress;
      try
      {
          ipaddress = System.Net.IPAddress.Parse(Ipadress);
      }
      catch
      {
          MessageBox.Show("IPThe address is entered incorrectly!");
          return 0;
      }
      return Convert.ToUInt32(ipaddress.Address);// Warning 4' System.Net.IPAddress.Address' is obsolete: 'This property has been deprecated. It is address family dependent. Please use IPAddress.Equals method to perform comparisons. 
  }


How do i to fix it? can you help me? plz. :D.
thank you for your attention :).

解决方案

You may have to use IPAddress.MapToIPv4 Method[^] instead.

return Convert.ToUInt32(Ipadress.MapToIPv4());


As a side note, Ipadress parameter should be named ipAddress; parameter names should be camel-cased. GetIpAdress should be named GetIpAddress as well.


这篇关于在c#中的getip中有警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆