1

Hello I have a Expression.GreaterThanOrEqual(left, right), so I want to evaluate string or domain types with data like :

002-1400

so when I use GreaterThanOrEqual operator ">=", I will be able to say 002-1400 "is greater or equal than" 002-1400, 002-1399, 002-1398 ... So I can play with some grid rows for compare via input parameters.

Hopes be understandable,

Thanks,

Jonathan Escobedo
  • 3,817
  • 12
  • 68
  • 90

4 Answers4

3

You cannot define operators on the String class. You can however create your own type and define equality relationships in any way you chose.

Ed S.
  • 119,398
  • 20
  • 176
  • 254
1

You would override it something like this:

public static operator >=(Foo foo1, Foo foo2)
{
    //code here...
}
public static operator ==(Foo foo1, Foo foo2)
{
    return foo1.Equals(foo2);
}
//etc... don't forget to implement Equals and GetHashCode!

see this question for hashcode implementing ideas.

Edit: Ed Swangren is right, you can't override an operator on a builtin class. You can, however, override it on your own classes!

Community
  • 1
  • 1
RCIX
  • 37,216
  • 48
  • 146
  • 206
0

Look for operator overloading. See MSDN: Operator Overloading Tutorial for example.

Matthias
  • 11,682
  • 4
  • 46
  • 88
0

You can to use operator overloading. See this link for a tutorial.

Rubens Farias
  • 55,782
  • 8
  • 132
  • 160