Answered by:
Determining operator in runtime

Question
-
User-1706989909 posted
Hi All,
Quite challenging requirement I have.
.
I have a class with stores LeftHandSideVaue, operator and result.
Operator can be like =, !=, >, < etc. Now is it possible to use it like variable1 operator variable2. Kindly let me know
Thanks
Monday, August 25, 2014 7:05 AM
Answers
-
User-1360095595 posted
You'll need to use an if block or a switch block to determine what operator is being used; something like:
switch (operation) { case ">": // do your processing for greater than break; case "<": // do your processing for less than break; etc... }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, August 25, 2014 7:51 AM
All replies
-
User-1360095595 posted
You'll need to use an if block or a switch block to determine what operator is being used; something like:
switch (operation) { case ">": // do your processing for greater than break; case "<": // do your processing for less than break; etc... }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, August 25, 2014 7:51 AM -
User-1706989909 posted
Thanks for reply.
Exactly this I did... expecting any other better solution if there.....
Monday, August 25, 2014 7:59 AM -
User724169276 posted
case is the best and efficient option here as per my understanding.
Monday, August 25, 2014 8:50 AM -
User-1151753377 posted
Hi Shil,
According to your description, you could try overriding the operator.
Please refer to link about how to override operator.
http://msdn.microsoft.com/en-us/library/aa288467(v=vs.71).aspx
If you have any other questions, please feel free to post this forum.
Best Regards,
Summer
Tuesday, August 26, 2014 1:14 AM