tags:

views:

89

answers:

4

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,

A: 

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

winSharp93
+3  A: 

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 Swangren
I have to create for example MyExpressions.GreaterThanOrEqual(p1,p2), and extends it from System.Linq.Expression thats right?
Angel Escobedo
A: 

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

Rubens Farias
+1  A: 

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!

RCIX