C# String Operator Overloading

前端 未结 7 2040
自闭症患者
自闭症患者 2020-12-19 04:02

G\'Day Mates -

What is the right way (excluding the argument of whether it is advisable) to overload the string operators <, >, <= and >= ?

I\'ve trie

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-19 04:26

    There is no way to replace any built-in behaviour of the compiler with your own. You cannot override existing built-in operators for comparisons, conversions, arithmetic, and so on. That's by design; it's so that someone can read your code and know that int x = M(); int y = x + 2; does integer arithmetic, as opposed to, say, formatting your hard disk.

    Can you explain why you want to do this? Perhaps there is a better way to do what you want.

提交回复
热议问题