Plurality in user messages

前端 未结 25 2027
没有蜡笔的小新
没有蜡笔的小新 2021-01-30 01:53

Many times, when generating messages to show to the user, the message will contain a number of something that I want to inform the customer about.

I\'ll give a

25条回答
  •  萌比男神i
    2021-01-30 02:49

    How about to write function like

    string GetOutputMessage(int count, string oneItemMsg, string multiItemMsg)
    {
     return string.Format("{0} {1}", count, count > 1 ? multiItemMsg : oneItemMsg);
    }
    

    .. and use it whenever you need?

    string message = "You have selected " + GetOutputMessage(noofitemsselected,"item","items") + ". Are you sure you want to delete it/them?";
    

提交回复
热议问题