How to Conditionally Format a String in .Net?

前端 未结 7 784
清酒与你
清酒与你 2020-12-16 09:50

I would like to do some condition formatting of strings. I know that you can do some conditional formatting of integers and floats as follows:

Int32 i = 0;
         


        
7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-16 10:28

    Not within String.Format(), but you could use C#'s inline operators, such as:

    return items.Count > 0 
           ? String.Format("Items: {0}; Values: {1}", itemList, valueList)
           : String.Format("Values: {0}", valueList);           
    

    This would help tidy-up the code.

提交回复
热议问题