Created
May 19, 2017 11:21
-
-
Save AkhmadMax/53457fae1f45f9d68d5136e33f93b315 to your computer and use it in GitHub Desktop.
Возвращает слова в падеже, зависимом от заданного числа
This file contains 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
public static class NumbersHelper | |
{ | |
/// <summary> | |
/// Возвращает слова в падеже, зависимом от заданного числа | |
/// </summary> | |
/// <param name="number">Число от которого зависит выбранное слово</param> | |
/// <param name="nominativ">Именительный падеж слова. Например "день"</param> | |
/// <param name="genetiv">Родительный падеж слова. Например "дня"</param> | |
/// <param name="plural">Множественное число слова. Например "дней"</param> | |
/// <returns></returns> | |
public static string GetDeclension(int number, string nominativ, string genetiv, string plural) | |
{ | |
number = number % 100; | |
if (number >= 11 && number <= 19) | |
{ | |
return plural; | |
} | |
var i = number % 10; | |
switch (i) | |
{ | |
case 1: | |
return nominativ; | |
case 2: | |
case 3: | |
case 4: | |
return genetiv; | |
default: | |
return plural; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment