New to Asp.Net Need connecting string and Add 2 values

Mohamed Rafi N 106 Reputation points
2022-03-15T04:52:34.023+00:00

Sir,

I am new to asp.net i have installed visual studio community 2022 i want to know how to add 2 values and display the output, i need step procedure. please guide me

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,312 questions
0 comments No comments
{count} votes

Accepted answer
  1. Lan Huang-MSFT 26,516 Reputation points Microsoft Vendor
    2022-03-16T09:30:09.67+00:00

    Hi @Mohamed Rafi N ,
    The type of textBox1.Text is string and cannot be directly equal to int type.
    If you use addition, you need to use the Convert.ToInt32 method to convert the specified value to a 32-bit signed integer.
    If you have other questions, please click comment.
    183579-1.jpg
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

6 additional answers

Sort by: Most helpful
  1. Mohamed Rafi N 106 Reputation points
    2022-03-16T10:40:19.353+00:00

    i have converted into string to integer then also it is not working

    int a, b, c;
    Convert.ToInt32(this.textBox1.Text);
    Convert.ToInt32(this.textBox2.Text);
    a = textBox1.Text;
    b = textBox2.Text;
    c = a + b;
    textBox3.Text = c;

    0 comments No comments

  2. AgaveJoe 26,166 Reputation points
    2022-03-16T11:07:43.667+00:00

    The syntax is...

    int a, b, c;  
    a = Convert.ToInt32(this.textBox1.Text);  
    b = Convert.ToInt32(this.textBox2.Text);  
    c = a + b;  
    textBox3.Text = c.ToString();  
    

    Reference documentation.
    Convert.ToInt32 Method

    I recommend int.TryParse().

    0 comments No comments