Connecting Tech Pros Worldwide Help | Site Map

Eval()

J.B.
Guest
 
Posts: n/a
#1: Nov 13 '05
Hi all.
I'm rather new to C#, (just learning ;-) and i'm making my own 'helper'
library, in wich i want to
have an eval(statement) function.

Anyone know how to make this / help me out on where to start?
Thanks.


Alex Bendig
Guest
 
Posts: n/a
#2: Nov 15 '05

re: Eval()


Something like
string eval(operand1, operand2, operator) { ... } ?

Basically, you could have different eval methods for different operand
types, such as:
string eval(int1, int2, operator) {}
string eval(double1, double2, operator) {}
....

Of course you could also use a function that simply takes object arguments:
string eval(object1, object2, operator) {...}

Within that particular method you could then simply check for the actual
type of the arguments (using GetType()) and proceed accordingly.

The operator would be a value representing any one of the opertors you would
like to support, such as "+", "-", "/", etc.

In the method body you then require a switch statement in which you check
for the actual operator and perform the appropriate operation with the
operands. You would then return a string representation of the result as the
result of the Eval() function.

Does that get you started?

Regards,
Alex

"J.B." <Nospam@spammer.nl> wrote in message
news:3f179210$0$49104$e4fe514c@news.xs4all.nl...[color=blue]
> Hi all.
> I'm rather new to C#, (just learning ;-) and i'm making my own 'helper'
> library, in wich i want to
> have an eval(statement) function.
>
> Anyone know how to make this / help me out on where to start?
> Thanks.
>
>[/color]


Closed Thread