Implementation of IpV4Address For legacy reason (guys here LOVE immutable object), I need a struct that contain an IpV4.

I can't use System.Net.IPAddress because it's not a struct.

So far here what I got:

public struct IpV4Address
{
    readonly byte[] address;

    public IpV4Address(byte[] address)
    {
        Throw.IfArgumentIsNull("address", address);

        if (address.Length != 4)
        {
            throw new ArgumentException("Wrong address length", "address");
        }

        this.address = new byte[4];
        Array.Copy(address, this.address, 4);
    }

    public override string ToString()
    {
        return string.Join(".", address);
    }

    /// &lt;summary&gt;
    ///     Parse a string representing an IPV4.
    ///     &lt;example&gt;xxx.yyy.zzz.www&lt;/example&gt;
    /// &lt;/summary&gt;
    /// &lt;param name="quadDotted"&gt;The string to parse.&lt;/param&gt;
    /// &lt;returns&gt;The IPV4&lt;/returns&gt;
    public static IpV4Address Parse(string quadDotted)
    {
        Throw.IfArgumentIsNull("quadDotted", quadDotted);

        var bytes = quadDotted.Split('.').Select(byte.Parse).ToArray();

        return new IpV4Address(bytes);
    }

    /// &lt;summary&gt;
    ///     Try parse a string representing an IPV4.
    ///     &lt;example&gt;xxx.yyy.zzz.www&lt;/example&gt;
    /// &lt;/summary&gt;
    /// &lt;param name="quadDotted"&gt;The string to parse.&lt;/param&gt;
    /// &lt;param name="result"&gt;The IPV4&lt;/param&gt;
    /// &lt;returns&gt;A value indicating whether the parse succeed.&lt;/returns&gt;
    public static bool TryParse(string quadDotted, out IpV4Address result)
    {
        if (quadDotted == null)
        {
            goto Fail;
        }

        var elements = quadDotted.Split('.');
        if (elements.Length != 4)
        {
            goto Fail;
        }

        var address = new byte[4];
        for (var i = 0; i &lt; 4; i++)
        {
            if (!byte.TryParse(elements[i], out address[i]))
            {
                goto Fail;
            }
        }

        result = new IpV4Address(address);
        return true;

        Fail:
        result = default(IpV4Address);
        return false;
    }


It's the first time I use a goto in a C# code. And I don't feel ashamed !
I find it more readable if you write the method like the following:

static bool TryParse(string quadDotted, out IpV4Address result)
{
    result = default(IpV4Address);

    if (quadDotted == null)
    {
        return false;
    }

    var elements = quadDotted.Split('.');
    if (elements.Length != 4)
    {
        return false;
    }

    var address = new byte[4];
    for (var i = 0; i &lt; 4; i++)
    {
        if (!byte.TryParse(elements[i], out address[i]))
        {
            return false;
        }
    }

    result = new IpV4Address(address);
    return true;
}


or:

static bool TryParse(string quadDotted, out IpV4Address result)
{
    bool canParse = false; 

    if (quadDotted != null)
    {
        var elements = quadDotted.Split('.');
        if (elements.Length == 4)
        {
            var address = new byte[4];

            // the following part can also be transformed in a do-while cycle
            canParse = byte.TryParse(elements[0], out address[0]);
            for (var i = 1; i &lt; 4 &amp;&amp; canParse; i++)
            {
                canParse = byte.TryParse(elements[i], out address[i]);
            }
        }
    }

    result = canParse ? new IpV4Address(address) : default(IpV4Address);
    return canParse;
}