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

前端 未结 14 1625
抹茶落季
抹茶落季 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:19

    I'm thinking the easiest way to do it is to create an Interface IPlural which has an method .ToString(int quantity) which returns the singular form when quantity == 1 an the plural form all other times.

提交回复
热议问题