C# String Operator Overloading

Posted by ScottSEA on Stack Overflow See other posts from Stack Overflow or by ScottSEA
Published on 2010-04-06T19:20:11Z Indexed on 2010/04/06 19:23 UTC
Read the original article Hit count: 275

Filed under:
|

G'Day Mates -

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

I've tried it five ways to Sunday and I get various errors - my best shot was declaring a partial class and overloading from there, but it won't work for some reason.

namespace System
{
   public partial class String
   {
       public static Boolean operator <(String a, String b)
       {
           return a.CompareTo(b) < 0;
       }

       public static Boolean operator >(String a, String b)
       {
           return a.CompareTo(b) > 0;
       }
   }

}

© Stack Overflow or respective owner

Related posts about operator-overloading

Related posts about c#