using System.Runtime.InteropServices;
[System.Runtime.InteropServices.StructLayout(LayoutKind.Explicit)]
[System.Runtime.InteropServices.FieldOffset(0)]
[System.Runtime.InteropServices.FieldOffset(0)]
[System.Runtime.InteropServices.FieldOffset(1)]
[System.Runtime.InteropServices.FieldOffset(2)]
[System.Runtime.InteropServices.FieldOffset(3)]
public IpAddress(int address) {
Byte1 = Byte2 = Byte3 = Byte4 = 0;
public override string ToString() {
return (new System.Text.StringBuilder()).Append(Byte1).Append('.')
.Append(Byte2).Append('.')
.Append(Byte3).Append('.')
.Append(Byte4).Append('.').ToString();
public static void Main()
var ip = new IpAddress((new Random()).Next());
Console.Out.WriteLine(ip + "\t= " + ip.intAddress);
Console.Out.WriteLine(ip + "\t= " + ip.intAddress);