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

  • Home
  • SEARCH
  • 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 8182401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:51:05+00:00 2026-06-07T00:51:05+00:00

I want to take a math expression that takes variables and print (assign to

  • 0

I want to take a math expression that takes variables and print (assign to string) the formula with the variables filled in.

int iTwo = 2;
int iResult = 0;

iResult = iTwo * iTwo;

string theString = (iTwo * iTwo).ToString();

In in the above code iResult = 4 and theString = “4”

I would like to do something that fills in the variables and returns the math expression like:

theString = (iTwo * iTwo).ExpressionToString();    

and end up with theString = “2 * 2”;

Thoughts?

  • 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-07T00:51:07+00:00Added an answer on June 7, 2026 at 12:51 am

    You could use the Expression<> type.

    public static string ExpressionToString<T>(Expression<Func<T>> e)
    {
        var un = e.Body as BinaryExpression;
        if (un != null)
        {
            var left = un.Left.ToString();
            var leftEnd = left.Split('.').LastOrDefault();
            var right = un.Right.ToString();
            var rightEnd = right.Split('.').LastOrDefault();
            return e.Body.ToString().Replace(left, leftEnd).Replace(right, rightEnd);
        }
        return e.Body.ToString();
    }
    
    Console.WriteLine(ExpressionToString(() => iTwo * iTwo));
    
    //prints (iTwo * iTwo)
    

    You’ll need to make the method more complex to parse things more complex than a simple binary expression, but that’s the general idea. You could just do e.Body.ToString(), but due to the way anonymous types are made for your lambdas, that can get ugly results, e.g.: "(value(TestApp.Program+<>c__DisplayClass3).iTwo * value(TestApp.Program+<>c__Dis
    playClass3).iTwo)"
    .

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

Sidebar

Related Questions

If I want to search those students who take class Math and John is
I want to take an array and use that array's values to populate an
I want to take two lists and find the values that appear in both.
I have a Big string which has multiple mathmls in it. Want to take
I want to take all the questions that were answered incorrectly (it's a simple
I don't want to take any more math in college than I have to,
I have an application that takes too long to run, and I want to
I want to take multiple integer inputs in same line eg :- input -1
I want to take advantage of the new features in Windows 7 using C#
I want to take a snapshot with my webcam using java and save it

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.