Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8215229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:42:46+00:00 2026-06-07T11:42:46+00:00

Imagine you have a function tree which has a number of nodes which can

  • 0

Imagine you have a function tree which has a number of nodes which can be either operator nodes (unary or binary operators), or terminal nodes (constants).

I’ve just started putting finger to keyboard and I’ve hit a small snag. I have created a Node interface, Operator:Node, BinaryOperator:Operator, UnaryOperator:Operator and Terminal:Node constructs.

And here I am with my problem. Do I now create a separate class for every foreseeable function? Do I create a SinOperator:UnaryOperator and CosOperator:UnaryOperator and AddOperator:BinaryOperator and so on? There are quite a few that can be considered if you include forward and inverse trig functions and their hyperbolic cousins.

Alternatively, I can just leave it at Binary and Unary operators and pass in a delegate which evaluates that node’s value based on it’s child nodes.

var sinOperator = new UnaryOperator(
                    childNode,
                    delegate()
                    {
                      return Math.Sin(childNode.GetValue());
                    });

But then there’s not really anything stopping me from putting all sorts of crazy stuff in the delegate, breaking the whole concept of it just being an operator.

Note: yes I realise that there are only a few operators (+-*/^√), and that sin/cos are actually functions… but for the purposes of this project we can assume that it is an operator

So how would you structure this in C#?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T11:42:49+00:00Added an answer on June 7, 2026 at 11:42 am

    Why don’t you take a look at how Linq.Expressions work? It’s an existing model of this (and the whole .NET language) in C#.

    Here you have a nice example of a Derivation program implemented using Linq.Expressions (You can check how it handles operators, sines, cosines, etc…)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine I have a class Window with a member function show which causes the
Imagine you have class A which has code which runs as method M. And
Imagine I have an function which goes through one million/billion strings and checks smth
Imagine I have a class in C# called Bar that has a public function
Possible Duplicate: C/C++: Passing variable number of arguments around Imagine I have a function
Imagine that I have a function in C that has 5 parameter. sum(n1,n2,n3,n4,n5); In
Imagine I have a template function like this: template<typename Iterator> void myfunc(Iterator a, typename
Imagine I have this code: var myFunc1 = function(event) { alert(1); } var myFunc2
Let's imagine I have an unknown function that I want to approximate via Genetic
imagine you have a function that creates/copies/moves files. [logic] For the case that a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.