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

后端 未结 12 678
情话喂你
情话喂你 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:58

    Slightly off topic, but I needed once for one of my classes to display 'Yes/No' instead of 'True/False' in a property grid, so I've implemented YesNoBooleanConverter derived from BooleanConverter and decorating my property with _...

提交回复
热议问题