/ Published in: C#
The switches are a little ugly, but they are quick.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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"; } } } }