What to do? Maybe some class need to add?

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication5 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { textBox1.Text = textBox1.Text += "1"; } private void button2_Click(object sender, EventArgs e) { textBox2.Text = textBox2.Text += "9"; } private void button3_Click(object sender, EventArgs e) { int a = Convert::ToInt32(this->textBox1.Text->Text); int b = Convert::ToInt32(this->textBox2.Text->Text); textBox3.Text = a+b; } } } 

Added.

After changing the code to (textBox3.Text = Convert::ToInt32(textBox1.Text)) + (Convert::ToInt32(textBox2.Text)); errors became 2. Only one mistake this:

The namespace qualifier "::" is always resolved to a type or namespace, which in this case is invalid. Consider using ".".

At Visual Studio 2010, I selected the very first item - Windows Forms = Visual C # Application.

  • The code in the studio - skegg
  • Part 1 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Windows FormsApplication5 {public partial class Form1: Form {public Form1 () {InitializeComponent (); } private void button1_Click (object sender, EventArgs e) {textBox1.Text = textBox1.Text + = "1"; } - navi1893
  • @ navi1893 Use question editing to add code. - Nicolas Chabanovsky
  • off topic: textBox1.Text = textBox1.Text += "1"; equivalent to textBox1.Text += "1"; on the topic: the class Convert is included in the System space, so in using `s nothing needs to be added and on the idea Convert::ToInt32(textBox2.Text); should work properly - Specter

4 answers 4

Just write

 textBox3.Text=(Convert.ToInt32(textBox1.Text)+Convert.ToInt32(textBox2.Text)).ToString(); 

And fix the label in C #.

  • Error: Implicit type conversion "int" to "string" is impossible - navi1893
  • Similarly, I forgot, updated the answer! - Specter
  • Finally! Thank you for everything, really you helped me a lot! PS can I add you to meil ru? - navi1893
  • Accept the answer, that will be enough. - Specter

Instead of "::" from C ++ to C # you need to use ".". A double colon in C # means something else. It should be used for namespace aliases. For example, there is a nested namespace of HashCode.GLMonster.Application . If you want to use it in the root namespace, you will have to write a long HashCode.GLMonster.Application.Variable . You can do this: using App=HashCode.GLMonster.Application , then this space can be accessed briefly by App::Variable .

By the way, the string into the text can still be converted via int.Parse .

    Connect the class Convert .

    • And where to add it? Here at the top in the comments I wrote the code, can you show it and then write it? - navi1893
    • C ++ has not studied for a long time, I may be mistaken, but try to finish it at the very beginning using System.Object.Convert or using.System.Convert - Alexander Kavokin
    • when using.System.Convert gives an error: The using namespace directive can only be applied to namespaces; "System.Convert" is a type, not a namespace - navi1893

    The class Convert is declared in the System namespace. It is already connected. Perhaps the call argument is undefined, try instead

     int a = Convert::ToInt32(this->textBox1.Text->Text); int b = Convert::ToInt32(this->textBox2.Text->Text); 

    to make

     int a = Convert::ToInt32("1"); int b = Convert::ToInt32("2"); 

    If the error disappears, something is wrong with this->textBox1.Text->Text and this->textBox2.Text->Text .

    • but right now this error in 2 places. The alias qualifier of the namespace "::" is always resolved to the type or namespace, which in this case is unacceptable. Consider using ".". and this one: The using namespace directive can only be applied to namespaces; "System.Convert" is a type, not a namespace - navi1893