Clever way to append 's' for plural form in .Net (syntactic sugar)

前端 未结 14 1648
抹茶落季
抹茶落季 2021-01-30 06:53

I want to be able to type something like:

Console.WriteLine(\"You have {0:life/lives} left.\", player.Lives);

instead of

Consol         


        
14条回答
  •  心在旅途
    2021-01-30 07:24

    I am using this extension method with .NET 4.6

    public static string Pluralize(this string @string)
    {
         if (string.IsNullOrEmpty(@string)) return string.Empty;
    
         var service = new EnglishPluralizationService();
    
         return service.Pluralize(@string);
    }
    

提交回复
热议问题