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

后端 未结 12 682
情话喂你
情话喂你 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-17 15:12

    Public Function TrueFalseToYesNo(thisValue As Boolean) As String
        Try
            If thisValue Then
                Return "Yes"
            Else
                Return "No"
            End If
        Catch ex As Exception
            Return thisValue.ToString
        End Try
    End Function
    

提交回复
热议问题