Search code examples
.netvisual-studioc++-cli

Type name not allowed (Convert)


I have two textBox, a button and a textBox where the result will be

#pragma endregion
    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
        double x = 0;
        double y = 0;
        double z = 0;
        x = Convert.ToDouble(textBox1->Text);   
        y = Convert.ToDouble(textBox2->Text);
        z = x + y;
        textBox3->Text = Convert.ToString(z);
    }

"Convert" write error number E0254


Solution

  • If ToDouble and ToString are static member functions then instead of

    x = Convert.ToDouble(textBox1->Text);   
    y = Convert.ToDouble(textBox2->Text);
    textBox3->Text = Convert.ToString(z);
    

    you need to write

    x = Convert::ToDouble(textBox1->Text);   
    y = Convert::ToDouble(textBox2->Text);
    textBox3->Text = Convert::ToString(z);