By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,876 Members | 1,291 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,876 IT Pros & Developers. It's quick & easy.

relational operator on basic type

P: n/a
I would like compare all type.
I try with this function but I get System.NullReference.Exception if
pass in Compare function two int type.

Why relational operation isn't defined for basic type as int?
How can I do?

private bool Compare(Object leftOperand,String op,Object rightOperand)
if (op.Equals(">"))
Type typeObject=leftOperand.GetType();
MethodInfo method = typeObject.GetMethod
("op_GreaterThan",BindingFlags.Public | BindingFlags.Static);
bool result=(bool) method.Invoke(leftOperand,objParam);
return result;

Nov 17 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
An explanation could be that int (.NET Int32) is a value type... it is
boxed/unboxed automatically and the comparison operator is directly
mapped to the cgt opcode so it does not need to override the relational
operator (op_GreaterThan is the overloaded operator method name).

I think that this is the answer...

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.