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,977
  • 12
  • 69
  • 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.
  • 122,712
  • 22
  • 185
  • 265
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
  • 38,647
  • 50
  • 150
  • 207
0

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

Matthias
  • 12,053
  • 4
  • 49
  • 91
0

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

Rubens Farias
  • 57,174
  • 8
  • 131
  • 162