最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#之IP地址和整數(shù)互轉(zhuǎn)的小例子

 更新時(shí)間:2013年03月11日 14:55:29   作者:  
C#之IP地址和整數(shù)互轉(zhuǎn)的小例子,需要的朋友可以參考一下

源碼:

復(fù)制代碼 代碼如下:

[StructLayout(LayoutKind.Explicit)]
 public struct IP
 {
     public IP(UInt32 value)
     {
         this._text1 = 0;
         this._text2 = 0;
         this._text3 = 0;
         this._text4 = 0;
         this._value = value;
     }
     public IP(Byte text1, Byte text2, Byte text3, Byte text4)
     {
         this._value = 0;
         this._text1 = text1;
         this._text2 = text2;
         this._text3 = text3;
         this._text4 = text4;
     }
     [FieldOffset(0)]
     private UInt32 _value;
     [FieldOffset(0)]
     private Byte _text1;
     [FieldOffset(1)]
     private Byte _text2;
     [FieldOffset(2)]
     private Byte _text3;
     [FieldOffset(3)]
     private Byte _text4;

     public UInt32 Value
     {
         get { return this._value; }
         set { this._value = value; }
     }
     public Byte Text1
     {
         get { return this._text1; }
         set { this._text1 = value; }
     }
     public Byte Text2
     {
         get { return this._text2; }
         set { this._text2 = value; }
     }
     public Byte Text3
     {
         get { return this._text3; }
         set { this._text3 = value; }
     }
     public Byte Text4
     {
         get { return this._text4; }
         set { this._text4 = value; }
     }

     public override string ToString()
     {
         return String.Format("{0}.{1}.{2}.{3}", this._text1.ToString(), this._text2.ToString(),
             this._text3.ToString(), this._text4.ToString());
     }

     public static implicit operator IP(UInt32 value)
     {
         return new IP(value);
     }
     public static explicit operator UInt32(IP ip)
     {
         return ip._value;
     }
 }

測(cè)試:

復(fù)制代碼 代碼如下:

class Program
 {
     static void Main(string[] args)
     {
         IP ip = new IP(192,168,1,1);
         Console.WriteLine(ip);
         UInt32 value = (UInt32)ip;
         Console.WriteLine(value);
         Console.WriteLine(ip.Value);
         IP ip2 = (IP)(1234567);
         Console.WriteLine(ip2);

         Console.ReadKey();
     }
 }

相關(guān)文章

最新評(píng)論

临漳县| 伊宁市| 澳门| 大邑县| 云南省| 蓝山县| 凤凰县| 徐闻县| 永清县| 大方县| 奉贤区| 高台县| 宁化县| 沙雅县| 泰和县| 金平| 江陵县| 玛纳斯县| 那坡县| 林甸县| 安岳县| 通化市| 凤冈县| 灵寿县| 罗源县| 来宾市| 义乌市| 富顺县| 正阳县| 桑日县| 棋牌| 丹阳市| 滨州市| 永兴县| 密山市| 务川| 灵寿县| 鹤山市| 合山市| 邢台市| 龙州县|