Ordinal Function - .NET Framework

See also: Ordinal Function - SQL Server

C#

public static string ToOrdinal(this int input)
{
    var mod100 = input % 100;
    var mod10 = input % 10;
    var result = input.ToString();

    if (mod10 == 1 & mod100 != 11)
        result += "st";
    else if (mod10 == 2 & mod100 != 12)
        result += "nd";
    else if (mod10 == 3 & mod100 != 13)
        result += "rd";
    else
        result += "th";

    return result;
}

Visual Basic

<Extension()>
Function GetOrdinal(n As Integer) As String

    Dim mod100 As Integer = n Mod 100
    Dim mod10 As Integer = n Mod 10
    Dim result As String = n.ToString()

    If mod10 = 1 And mod100 <> 11 Then
        result += "st"
    ElseIf mod10 = 2 And mod100 <> 12 Then
        result += "nd"
    ElseIf mod10 = 3 And mod100 <> 13 Then
        result += "rd"
    Else
        result += "th"
    End If

    Return result

End Function