Operator denoted by a character? Well, well…
This sounds like a really bad approach. By some reason, one worst misconception haunts the beginners: an attempt to use strings representing data, instead of data itself. And in this case, you are trying to use string instead of code. Is it even worse? I don't know, anyway, very bad…
Do you at least understand: should you misspell the "operator" character, the compiler won't warn you on the bug?
You can use a very simple and productive approach instead. Instead of "operator" (which is actually not, in your case),
pass a delegate instance implementing the operator.
Are you getting the idea? Let's see:
static bool MyMethod(int left, int right, System.Func<int, int, bool> userPredicate) {
bool result = userPredicate(left, right);
return result;
}
Now, how to use it in the call? Let's see:
static void Test() {
bool greater = MyMethod(2, 1, (l, r) => l > r);
bool equal = MyMethod(4, 4, (l, r) => l == r);
}
Simple enough, isn't it?
—SA