.NET的ToString()格式的文档格式、文档、NET、ToString

2023-09-04 01:11:30 作者:此女↗无可取

我看到一个code片段,一个布尔值转换为前些天相应的是/否值:

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")

在code正常工作,但我很好奇它是如何工作,我一直没能找到在的 MSDN文档的ToString()。

任何人都可以揭示出这个一些轻?

Can anybody shed some light on this?

推荐答案

它是把它当作一个自定义数字格式字符串。具体而言,看到的链接页面部分分离的部分:

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.