Не могу поправить ошибку в коде

Вот сам код

using System;
using Android.App;
using Android.OS;
using System.Data;
using Android.Runtime;
using Android.Support.Design.Widget;
using Android.Support.V7.App;
using Android.Views;
using Android.Widget;
using Android.Content;

namespace App3
{
    [Activity(Label = "App3", Theme = "@style/AppTheme.NoActionBar", MainLauncher = true)]
    public class MainActivity : AppCompatActivity
    {



        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.activity_main);
           
             //Buttons to receive user input
            Button num1 = (Button)FindViewById(Resource.Id.btn1);
            Button num2 = (Button)FindViewById(Resource.Id.btn2);
            Button num3 = (Button)FindViewById(Resource.Id.btn3);
            Button num4 = (Button)FindViewById(Resource.Id.btn4);
            Button num5 = (Button)FindViewById(Resource.Id.btn5);
            Button num6 = (Button)FindViewById(Resource.Id.btn6);
            Button num7 = (Button)FindViewById(Resource.Id.btn7);
            Button num8 = (Button)FindViewById(Resource.Id.btn8);
            Button num9 = (Button)FindViewById(Resource.Id.btn9);
            Button num0 = (Button)FindViewById(Resource.Id.btn0);
            
            //Buttons that receive user mathematical operators
            Button equ = (Button)FindViewById(Resource.Id.btnEql);
            Button clr = (Button)FindViewById(Resource.Id.btnDel);
            Button dot = (Button)FindViewById(Resource.Id.btnDot);
            Button div = (Button)FindViewById(Resource.Id.btnDiv);
            Button mul = (Button)FindViewById(Resource.Id.btnMul);
            Button add = (Button)FindViewById(Resource.Id.btnAdd);
            Button sub = (Button)FindViewById(Resource.Id.btnSub);

            //text area to receive and display the user input
            EditText resu = (EditText)FindViewById(Resource.Id.resultText);
            
            //Text area to display the result generated after calculations
            EditText resu2 = (EditText)FindViewById(Resource.Id.resultText2);
            
            //Whenever the text in the EditText Changes the expression in the EditText is being computed.
            resu.TextChanged += delegate 
            {

                if (resu.Text == "")
                {
                    resu2.Text = "";
                }

                string x = resu.Text;
                try
                {
                    //Computation of the expression
                    double result = Convert.ToDouble(new DataTable().Compute(x, null));
                    resu2.Text = result.ToString();
                }
                catch (Exception exc)
                {
                    //No action to be performed
                }
            };

            num1.Click += delegate { resu.Text = resu.Text + num1.Text.ToString(); };
            num2.Click += delegate { resu.Text = resu.Text + num2.Text.ToString(); };
            num3.Click += delegate { resu.Text = resu.Text + num3.Text.ToString(); };
            num4.Click += delegate { resu.Text = resu.Text + num4.Text.ToString(); };
            num5.Click += delegate { resu.Text = resu.Text + num5.Text.ToString(); };
            num6.Click += delegate { resu.Text = resu.Text + num6.Text.ToString(); };
            num7.Click += delegate { resu.Text = resu.Text + num7.Text.ToString(); };
            num8.Click += delegate { resu.Text = resu.Text + num8.Text.ToString(); };
            num9.Click += delegate { resu.Text = resu.Text + num9.Text.ToString(); };
            num0.Click += delegate { resu.Text = resu.Text + num0.Text.ToString(); };

            dot.Click += delegate 
            {
                string x = resu.Text;
                int l = x.Length;
                if (l != 0)
                {
                    string x2 = x.Substring(l - 1, 1);
                    if (x2 != ".")
                    {
                        if (x2 == "-" || x2 == "*" || x2 == "/" || x2 == "+")
                        {
                            string s1 = x.Substring(0, l - 1);
                            resu.Text = s1;
                        }
                        resu.Text = resu.Text + dot.Text.ToString();
                    }
                }
            };

            add.Click += delegate 
            {
                string x = resu.Text;
                int l = x.Length;
                if (l != 0)
                {
                    string x2 = x.Substring(l - 1, 1);
                    if (x2 != "+")
                    {
                        if (x2 == "-" || x2 == "*" || x2 == "/" || x2 == ".")
                        {
                            string s1 = x.Substring(0, l - 1);
                            resu.Text = s1;
                        }
                        resu.Text = resu.Text + add.Text.ToString();
                    }
                }
            };
            sub.Click += delegate 
            {
                string x = resu.Text;
                int l = x.Length;
                if (l != 0)
                {
                    string x2 = x.Substring(l - 1, 1);
                    if (x2 != "-")
                    {
                        if (x2 == "+" || x2 == "*" || x2 == "/" || x2 == ".")
                        {
                            string s1 = x.Substring(0, l - 1);
                            resu.Text = s1;
                        }
                        resu.Text = resu.Text + sub.Text.ToString();
                    }
                }
            };
            mul.Click += delegate 
            {
                string x = resu.Text;
                int l = x.Length;
                if (l != 0)
                {
                    string x2 = x.Substring(l - 1, 1);
                    if (x2 != "*")
                    {
                        if (x2 == "-" || x2 == "+" || x2 == "/" || x2 == ".")
                        {
                            string s1 = x.Substring(0, l - 1);
                            resu.Text = s1;
                        }
                        resu.Text = resu.Text + "*";
                    }
                }
            };
            div.Click += delegate 
            {
                string x = resu.Text;
                int l = x.Length;
                if (l != 0)
                {
                    string x2 = x.Substring(l - 1, 1);
                    if (x2 != "/")
                    {
                        if (x2 == "-" || x2 == "*" || x2 == "+" || x2 == ".")
                        {
                            string s1 = x.Substring(0, l - 1);
                            resu.Text = s1;
                        }
                        resu.Text = resu.Text + div.Text.ToString();
                    }
                }
            };
            clr.Click += delegate 
            {
                string x = resu.Text;
                int l = x.Length;
                if (l != 0)
                {
                    string x2 = x.Substring(0, l - 1);
                    resu.Text = x2;
                    if (x2.Length != 0)
                    {
                        string x3 = x2.Substring(l - 2, 1);
                        if (x3 == "+" || x3 == "-" || x3 == "*" || x3 == "/" || x3 == ".")
                        {
                            try
                            {
                                double result = Convert.ToDouble(new DataTable().Compute(x.Substring(0, l - 2), null));
                                resu2.Text = result.ToString();
                            }
                            catch (Exception exc)
                            {
                            }
                        }
                    }
                }
            };
            equ.Click += delegate 
            {
                if (resu2.Text != "")
                {
                    resu.Text = resu2.Text;
                    resu2.Text = "";
                }
            };

        }

        private void Resu_TextChanged(object sender, Android.Text.TextChangedEventArgs e)
        {
            throw new System.NotImplementedException();
        }
        
       
    }
}

Файл csproj

 <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>8.0.30703</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{3BC0AC7E-3B3B-4D3F-9CC0-B2BDECC460A6}</ProjectGuid>
    <ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
    <TemplateGuid>{84dd83c5-0fe3-4294-9419-09e7c8ba324f}</TemplateGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>App3</RootNamespace>
    <AssemblyName>App3</AssemblyName>
    <FileAlignment>512</FileAlignment>
    <AndroidApplication>True</AndroidApplication>
    <AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
    <AndroidResgenClass>Resource</AndroidResgenClass>
    <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
    <AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
    <TargetFrameworkVersion>v8.1</TargetFrameworkVersion>
    <AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
    <MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
    <MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
    <AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>True</DebugSymbols>
    <DebugType>portable</DebugType>
    <Optimize>False</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <AndroidUseSharedRuntime>True</AndroidUseSharedRuntime>
    <AndroidLinkMode>None</AndroidLinkMode>
    <EmbedAssembliesIntoApk>False</EmbedAssembliesIntoApk>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>PdbOnly</DebugType>
    <DebugSymbols>True</DebugSymbols>
    <Optimize>True</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <AndroidManagedSymbols>true</AndroidManagedSymbols>
    <AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>
    <AndroidLinkMode>SdkOnly</AndroidLinkMode>
    <EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Xml" />
    <Reference Include="System.Core" />
    <Reference Include="Mono.Android" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="MainActivity.cs" />
    <Compile Include="Resources\Resource.designer.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="Resources\AboutResources.txt" />
    <None Include="Properties\AndroidManifest.xml" />
    <None Include="Assets\AboutAssets.txt" />
  </ItemGroup>
  <ItemGroup>
    <AndroidResource Include="Resources\layout\activity_main.axml">
      <SubType>Designer</SubType>
    </AndroidResource>
    <AndroidResource Include="Resources\values\colors.xml" />
    <AndroidResource Include="Resources\values\dimens.xml" />
    <AndroidResource Include="Resources\values\ic_launcher_background.xml" />
    <AndroidResource Include="Resources\values\strings.xml" />
    <AndroidResource Include="Resources\values\styles.xml" />
    <AndroidResource Include="Resources\menu\menu_main.xml" />
    <AndroidResource Include="Resources\mipmap-anydpi-v26\ic_launcher.xml" />
    <AndroidResource Include="Resources\mipmap-anydpi-v26\ic_launcher_round.xml" />
    <AndroidResource Include="Resources\mipmap-hdpi\ic_launcher.png" />
    <AndroidResource Include="Resources\mipmap-hdpi\ic_launcher_foreground.png" />
    <AndroidResource Include="Resources\mipmap-hdpi\ic_launcher_round.png" />
    <AndroidResource Include="Resources\mipmap-mdpi\ic_launcher.png" />
    <AndroidResource Include="Resources\mipmap-mdpi\ic_launcher_foreground.png" />
    <AndroidResource Include="Resources\mipmap-mdpi\ic_launcher_round.png" />
    <AndroidResource Include="Resources\mipmap-xhdpi\ic_launcher.png" />
    <AndroidResource Include="Resources\mipmap-xhdpi\ic_launcher_foreground.png" />
    <AndroidResource Include="Resources\mipmap-xhdpi\ic_launcher_round.png" />
    <AndroidResource Include="Resources\mipmap-xxhdpi\ic_launcher.png" />
    <AndroidResource Include="Resources\mipmap-xxhdpi\ic_launcher_foreground.png" />
    <AndroidResource Include="Resources\mipmap-xxhdpi\ic_launcher_round.png" />
    <AndroidResource Include="Resources\mipmap-xxxhdpi\ic_launcher.png" />
    <AndroidResource Include="Resources\mipmap-xxxhdpi\ic_launcher_foreground.png" />
    <AndroidResource Include="Resources\mipmap-xxxhdpi\ic_launcher_round.png" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="System.Data.Common">
      <Version>4.3.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Android.Support.Design" Version="27.0.2.1" />
  </ItemGroup>
  <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
    Other similar extension points exist, see Microsoft.Common.targets.
    <Target Name="BeforeBuild">
    </Target>
    <Target Name="AfterBuild">
    </Target>
  -->
</Project>

Ошибки в этих строках

    double result = Convert.ToDouble(new DataTable().Compute(x, null));
 double result = Convert.ToDouble(new DataTable().Compute(x.Substring(0, l - 2), null));

Конкретно ругается на new DataTable() - Не удалось найти тип или имя пространства имен DataTable


Ответы (1 шт):

Автор решения: dima121181

Вместо DataTable можете создать собственный метод для конвертации в любой тип. Вот пример метода для конвертации в Double.

public static double GetDouble (object value, double DefValue) {
  try {
    if (value != DBNull.Value && value != null)
      return Convert.ToDouble(value);
    return DefValue;
  } catch {
    return DefValue;
  }
}
→ Ссылка