0

I have this TextBox where you can type in something like "1 + 2 + 3". I want the program to evaluate the answer (6 in this case) and assign it to a var. Then output the answer to a TextBlock. Tried the following but I'm getting a red underline under DataTable. It says 'DataTable' does not contain a constructor that takes 0 arguments

using System.Data;

    private void ButtonCalculate_Click(object sender, RoutedEventArgs e)
    {
        string equation = textBoxEquation.Text;
        var answer = new DataTable().Compute(equation, "");
        textBlockAnswer.Text = answer;
    }
EsAMe
  • 305
  • 2
  • 13
  • 1
    Please [edit] your question to include the full source code you have as a [mcve]. It looks like you referencing the wrong `DataTable` class, it should be the one from `System.Data.DataTable`. – Progman Aug 17 '19 at 10:28
  • @Progman yes, I got the solution from that thread but it's not working. for the error I faced, see my questions details. – EsAMe Aug 17 '19 at 11:18
  • @Progman I have added full source code. It's a simple UWP app with a button, textbox and textblock. – EsAMe Aug 17 '19 at 11:25
  • It looks like you are using a different `DataTable` class. Please hover over the `new DataTable()`" statement to see which class is recognized. Fix the imports or force the issue by using `new System.Data.DataTable()`. – Progman Aug 17 '19 at 11:39
  • @Progman Can you write the answer because I'm not sure what you mean. I removed the using and typed the full new System.Data.DataTable(). This resulted in the same 0 arguments error. – EsAMe Aug 17 '19 at 11:46
  • Please edit your question to include the **full, complete** source code you have as a [mcve], that can be compiled by everyone else (or compile as far as possible). Also include the list of constructors, you can use for the `DataTable` class instead. It complains that the constructor with zero arguments does not exists, but are there other constructors available? List each constructor in your question, maybe even take a screenshot of your IDEs code intellisense for the constructors you can use. Also check with the mouse cursor which class and namespace is recognized by `new DataTable()`. – Progman Aug 17 '19 at 11:53

1 Answers1

0

I solved this by:

  1. Right click project name in Solution Explorer
  2. Choose Properties
  3. Target the Min version to at least Fall Creators Update
EsAMe
  • 305
  • 2
  • 13