Int16 - HostToNetworkOrder

Converts a short value from host byte order to network byte order.

Try it

public static void Main()
{
    Int16  input = 57;
	
	// C# Extension Method: Int16 - HostToNetworkOrder
	Int16  output = input.HostToNetworkOrder();
    Console.WriteLine("val = {0}, output = {1}", input, output);
}

View Source
using System;
using System.Net;

public static partial class Extensions
{
    /// <summary>
    ///     Converts a short value from host byte order to network byte order.
    /// </summary>
    /// <param name="host">The number to convert, expressed in host byte order.</param>
    /// <returns>A short value, expressed in network byte order.</returns>
    public static Int16 HostToNetworkOrder(this Int16 host)
    {
        return IPAddress.HostToNetworkOrder(host);
    }
}