Created
May 15, 2016 13:45
-
-
Save insideone/2c4172e6023a2b9ac07a0dbec61f4373 to your computer and use it in GitHub Desktop.
C#: Склонение существительного после числительного
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int i = 3; | |
Console.WriteLine(i.Decline("Прошёл", "Прошло", "Прошло") + " " + i.ToString() + " " + i.Decline("час", "часа", "часов")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class IntegerExtend | |
{ | |
/// <summary> | |
/// Склоняет существительное в зависимости от числительного идущего перед ним. | |
/// </summary> | |
/// <param name="num">Число идущее перед существительным.</param> | |
/// <param name="normative">Именительный падеж слова.</param> | |
/// <param name="singular">Родительный падеж ед. число.</param> | |
/// <param name="plural">Множественное число.</param> | |
public static string Decline(this int num, string nominative, string singular, string plural) | |
{ | |
if (num > 10 && ((num % 100) / 10) == 1) return plural; | |
switch (num % 10) | |
{ | |
case 1: | |
return nominative; | |
case 2: | |
case 3: | |
case 4: | |
return singular; | |
default: // case 0, 5-9 | |
return plural; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment