.net ToString() format documentation

后端 未结 5 1413
感情败类
感情败类 2021-02-20 08:06

I saw a code snippet the other day that converts a Boolean value to the corresponding \"Yes\"/\"No\" value:

CDbl(True).ToString(\"Yes;Yes;No\")

5条回答
  •  生来不讨喜
    2021-02-20 08:39

    It's treating it as a Custom Numeric Format String. Specifically, see the part about section separators in the linked page:

    The ';' character is used to separate sections for positive, negative, and zero numbers in the format string. If there are two sections in the custom format string, the leftmost section defines the formatting of positive and zero numbers, while the rightmost section defines the formatting of negative numbers. If there are three sections, the leftmost section defines the formatting of positive numbers, the middle section defines the formatting of negative numbers, and the rightmost section defines the formatting of zero numbers.

提交回复
热议问题