欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

源碼:

復制代碼 代碼如下:

[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;
     }
 }

測試:

復制代碼 代碼如下:

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

相關文章

  • C#中ListView用法實例

    C#中ListView用法實例

    我們經(jīng)常會在應用程序中使用列表的形式來展現(xiàn)一些內(nèi)容,所以學好ListView是非常必需的,下面這篇文章主要給大家介紹了關于C#中ListView用法的相關資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-06-06
  • C#中的Socket編程詳解

    C#中的Socket編程詳解

    本文詳細講解了C#中的Socket編程,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-01-01
  • Unity實現(xiàn)圖片輪播組件

    Unity實現(xiàn)圖片輪播組件

    這篇文章主要為大家詳細介紹了Unity實現(xiàn)圖片輪播組件的相關方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-03-03
  • WinForm實現(xiàn)按名稱遞歸查找控件的方法

    WinForm實現(xiàn)按名稱遞歸查找控件的方法

    這篇文章主要介紹了WinForm實現(xiàn)按名稱遞歸查找控件的方法,需要的朋友可以參考下
    2014-08-08
  • c# 委托的常見用法

    c# 委托的常見用法

    這篇文章主要介紹了c# 委托的常見用法,幫助大家更好的理解和學習c#,感興趣的朋友可以了解下
    2020-08-08
  • Entity?Framework配置關系

    Entity?Framework配置關系

    這篇文章介紹了Entity?Framework配置關系的方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-06-06
  • C# String Replace高效的實例方法

    C# String Replace高效的實例方法

    C# String Replace高效的實例方法,需要的朋友可以參考一下
    2013-05-05
  • C#如何實現(xiàn)調(diào)取釘釘考勤接口的功能

    C#如何實現(xiàn)調(diào)取釘釘考勤接口的功能

    這篇文章主要介紹了C#如何實現(xiàn)調(diào)取釘釘考勤接口的功能,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • C#中winform中panel重疊無法顯示問題的解決

    C#中winform中panel重疊無法顯示問題的解決

    這篇文章主要介紹了C#中winform中panel重疊無法顯示問題的解決,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-10-10
  • 利用C#實現(xiàn)將小數(shù)值四舍五入為整數(shù)

    利用C#實現(xiàn)將小數(shù)值四舍五入為整數(shù)

    在項目的開發(fā)中,遇到一些除法計算內(nèi)容會產(chǎn)生小數(shù)值,但是又需要根據(jù)項目的實際情況將這些小數(shù)內(nèi)容化為整數(shù),所以本文為大家整理了C#實現(xiàn)將小數(shù)值四舍五入為整數(shù)的方法,希望對大家有所幫助
    2023-07-07

最新評論