Can .NET convert “Yes” & “No” to boolean without If?

后端 未结 12 698
情话喂你
情话喂你 2020-12-17 14:15

You would think there would be a way using DirectCast, TryCast, CType etc but all of them seem to choke on it e.g.:

CType(\"Yes\", Boolean)

12条回答
  •  渐次进展
    2020-12-17 14:51

    If you think about it, "yes" cannot be converted to bool because it is a language and context specific string.

    "Yes" is not synonymous with true (especially when your wife says it...!). For things like that you need to convert it yourself; "yes" means "true", "mmmm yeeessss" means "half true, half false, maybe", etc.

提交回复
热议问题