当前位置:编程学习 > C#/ASP.NET >>

求把这句翻译成C#语言


    Public Function NumToIp(Num As Currency) As String
        Dim Tmp As Currency
        Dim Ip As String
        Dim IpByte As Integer
        Tmp = Int(Num / 256)
        IpByte = Num - Tmp * 256
        Ip = "." & CStr(IpByte)
        Num = Tmp
        Tmp = Int(Num / 256)
        IpByte = Num - Tmp * 256
        Ip = "." & CStr(IpByte) & Ip
        Num = Tmp
        Tmp = Int(Num / 256)
        IpByte = Num - Tmp * 256
        Ip = Tmp & "." & CStr(IpByte) + Ip
        NumToIp = Ip
    End Function

--------------------编程问答-------------------- string numtostring(int ip)
{
    return string.Join(".", BitConvert.GetBytes(ip).Select(x => x.ToString()).Reverse().ToArray());
} --------------------编程问答-------------------- vb.net->C#
http://www.developerfusion.com/tools/convert/vb-to-csharp/?batchId=c82f11d2-5bf1-498d-8442-f28097ff177c
对应转换:
 
public string NumToIp(int Num)
     {
         int Tmp;
         string Ip = null;
         int IpByte = 0;
         Tmp = Convert.ToInt16(Num / 256);
         IpByte = Num - Tmp * 256;
         Ip = "." + Convert.ToString(IpByte);
         Num = Tmp;
         Tmp = Convert.ToInt16(Num / 256);
         IpByte = Num - Tmp * 256;
         Ip = "." + Convert.ToString(IpByte) + Ip;
         Num = Tmp;
         Tmp = Convert.ToInt16(Num / 256);
         IpByte = Num - Tmp * 256;
         Ip = Tmp + "." + Convert.ToString(IpByte) + Ip;
         return Ip;
     }
/////////
1楼的简单,不过有一个地方错了, BitConvert应是 BitConverter
 return string.Join(".", BitConverter.GetBytes(ip).Select(x => x.ToString()).Reverse().ToArray());
--------------------编程问答-------------------- http://www.developerfusion.com/tools/convert/vb-to-csharp/?batchId=c82f11d2-5bf1-498d-8442-f28097ff177c
这个网站可以转换! --------------------编程问答-------------------- http://www.developerfusion.com/tools/convert/csharp-to-vb/
自己转吧 --------------------编程问答-------------------- 额,不需要转换,如果你知道ip2long,long2ip的规则自己写比这个还好!

呵呵,简单的左移,右移即可。当然微软自己也有成品类, IPAddress.Parse(long ip).ToString()即可 --------------------编程问答--------------------
引用 2 楼 wind_cloud2011 的回复:
vb.net->C#
http://www.developerfusion.com/tools/convert/vb-to-csharp/?batchId=c82f11d2-5bf1-498d-8442-f28097ff177c
对应转换:
 
public string NumToIp(int Num)
     {
         int Tmp;
         string Ip = null;
         int IpByte = 0;
         Tmp = Convert.ToInt16(Num / 256);
         IpByte = Num - Tmp * 256;
         Ip = "." + Convert.ToString(IpByte);
         Num = Tmp;
         Tmp = Convert.ToInt16(Num / 256);
         IpByte = Num - Tmp * 256;
         Ip = "." + Convert.ToString(IpByte) + Ip;
         Num = Tmp;
         Tmp = Convert.ToInt16(Num / 256);
         IpByte = Num - Tmp * 256;
         Ip = Tmp + "." + Convert.ToString(IpByte) + Ip;
         return Ip;
     }
/////////
1楼的简单,不过有一个地方错了, BitConvert应是 BitConverter
 return string.Join(".", BitConverter.GetBytes(ip).Select(x => x.ToString()).Reverse().ToArray());

是的,谢谢指出。 --------------------编程问答-------------------- mark一下,bitconverter
补充:.NET技术 ,  VB.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,