Kapil Gaur
Create a textbox calculator in C# in the fastest way possible with minimal lines of code. Whatever expression a user writes in the textbox, it should be evaluated and the result should be shown.
By Kapil Gaur in .NET on Oct 24 2018
  • Kapil Gaur
    Oct, 2018 24

    So for this we can use compute method of Data Table class. lets assume you have a textbox with ID Textbox1 to enter the expression. Then a Calculate button and a result Textbox2 to show the result. So you can do this as follows. In your code behind file writeusing System.Data; //On button click you have to write these lines DataTable dt = new DataTable(); Textbox2.Text=dt.Compute(Textbox1.Text,"");By using just 3 lines of code you will have with you a working calculator which can evaluate any arithmetic expression.

    • 5
  • Laxmidhar Sahoo
    Nov, 2018 1

    Kapil is correct .You can make it in one line like textBox2.Text = new DataTable().Compute(textBox1.Text, "").ToString();

    • 0

Most Popular Job Functions