麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁(yè) > 編程 > C# > 正文

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

2020-01-24 03:33:22
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

源碼:

復(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();
     }
 }

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: www.91sese| 激情影院在线观看 | 色网站免费观看 | 精品久久久久久久久久久久久久 | av色偷偷 | 黄色网址在线免费 | 国内精品久久久久久2021浪潮 | 成人在线观看免费观看 | 思思久而久而蕉人 | 国产人成免费爽爽爽视频 | 一级美女大片 | 男人的天堂视频网站 | 成人情欲视频在线看免费 | 国产成人综合在线观看 | 中国免费一级毛片 | 国内精品久久久久久久星辰影视 | 经典三级在线视频 | 七首小情歌泰剧在线播放 | 精品一区二区三区免费视频 | 九九热精 | 男男羞羞视频网站国产 | 狠狠干天天操 | 精品久久久久久久久久久久包黑料 | 亚洲成人在线视频网 | 羞羞网站在线看 | av电影在线免费 | 精品国产精品久久 | 午夜爽爽爽男女免费观看hd | 九草在线| 久久久久99一区二区三区 | 久久成人在线观看 | 亚洲国产精品一区二区三区 | 国产亚洲精品美女久久久 | 久草成人在线 | 中文字幕 日本 | 国产又粗又爽又深的免费视频 | 天天黄色片 | 草草影院地址 | 亚洲综合无码一区二区 | 欧美一级特黄a | 精品国产91久久久久久久 |