Can I format NULL values in string.Format?

前端 未结 5 1969
粉色の甜心
粉色の甜心 2021-01-01 08:55

I was wondering if there\'s a syntax for formatting NULL values in string.Format, such as what Excel uses

For example, using Excel I could specify a format value of

5条回答
  •  醉酒成梦
    2021-01-01 09:31

    It looks like String.Format for .NET acts the same way as Excel, i.e., you can use ; separator for positive, negative, and 0 values, but not NULL: http://msdn.microsoft.com/en-us/library/0c899ak8.aspx#SectionSeparator.

    You will probably just have to handle the null value manually:

    if (myval == null)
        // handle
    else
        return String.Format(...);
    

提交回复
热议问题