C# Can a comparison in a String value return a Boolean value. eg. “5 < 10” return true

后端 未结 6 1742
故里飘歌
故里飘歌 2020-12-22 14:11

Is there a way a comparison in a string value can return a Boolean value. Example. If (5 > 5000) would obviously return a false value. But what i wanted to do i

6条回答
  •  攒了一身酷
    2020-12-22 14:38

    No, this can't be done directly. You should write your own class or extend the String class. For handling a string such as "5 < 10", you need your own method.

    You should search the string for signs that indicate comparison, such as "<", "==" etc, then split it and perform the comparison.

    Basically: doing it yourself is the only way, but you can try to do it in an elegant way.

提交回复
热议问题