Alternative to VB.NET's Type Conversion functions (CBool) in C#?

后端 未结 3 1430
难免孤独
难免孤独 2021-01-19 07:26

Is there any alternative to VB\'s CBool keyword in C#?

What about all the other functions?

CBool will turn to a Boolean any valid boolean:

3条回答
  •  自闭症患者
    2021-01-19 07:58

    If you expect to be converting from one of the string values: "True", "true", "False", or "false", you should use Boolean.Parse. Instead of trying to be "smart" about it, Parse will "fail fast" if it doesn't get what it expects. By using a "smart" conversion when you don't really need it, you may mask errors at their source then have to track them down when they appear later in the code, which is usually more difficult.

提交回复
热议问题