---
title: "How to create an application to solve an expression"  
description: "How to create an application to solve an expression"  
author: "Simond Gear"  
published: 2016-11-27  
updated: 2016-11-28  
canonical: https://www.mindstick.com/forum/34211/how-to-create-an-application-to-solve-an-expression  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# How to create an application to solve an expression

Hi Buddy\
Please help me how to create an [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) to solve an expression.\
Thanks

## Replies

### Reply by Abhishek Srivasatava

Hi Simond,

I have generated the code to solve the expression which is written in the textbox. Please review it and let us know if any information is required.

\

```
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms; namespace
WindowsFormsApplication2{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private object
CalculateExpression(string eqn)        {            string test = eqn.Replace("{", "(").Replace("}", ")").Replace("[", "(").Replace("]", ")");            string test2 = test.Replace(")", ")*").Replace("(", "*(");            string test3 = test2.Replace("**", "*");            char[] ch = new char[100];            ch = test3.ToCharArray();            int a = test3.Length;            a = a - 1;            if (ch[a] == '*')            {                ch[a] = ' ';            }            if (ch[0] == '*')            {                ch[0] = ' ';            }            string test4 = new string(ch);             string test5 = test4.Replace("/*", "/").Replace("*/", "/").Replace("+*", "+").Replace("*+", "+").Replace("-*", "-").Replace("*-", "*").Replace("(*", "(").Replace("*)", ")").Replace("**", "*");            eqn = test5.Trim();             DataTable dt = new DataTable();            var result = dt.Compute(eqn, string.Empty);            return result;        }           private void Form1_Load(object sender, EventArgs e)        {         }         private void button1_Click(object sender, EventArgs e)        {            try            {                 string result = Convert.ToString(CalculateExpression(textBox1.Text.Trim()));                textBox2.Text = result;                textBox2.ForeColor =
Color.Blue;            }            catch (Exception ex)            {                textBox2.Text = "Please
Review your Expression" + ex.Message.ToString();                textBox2.ForeColor = Color.Red;            }        }    }}
```


---

Original Source: https://www.mindstick.com/forum/34211/how-to-create-an-application-to-solve-an-expression

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
