Revision: 13792
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at May 6, 2009 10:34 by jmcd
Initial Code
public static class IntExtensions
{
public static string GetOrdinalSuffix(this int @this)
{
switch (@this % 100)
{
case 11:
case 12:
case 13:
return "th";
default:
switch (@this % 10)
{
case 1:
return "st";
case 2:
return "nd";
case 3:
return "rd";
default:
return "th";
}
}
}
}
Initial URL
Initial Description
The switches are a little ugly, but they are quick.
Initial Title
Ordinal suffix of an integer
Initial Tags
Initial Language
C#