Add Two Numbers and Display Sum in C#
It is a simple C# program to add two integers and display their sum. This program is only for learning C#.
Here two text boxes will accept two numbers from user and display their sum in another text box.

Interface:
Add Two Numbers and Display Sum in C#
Code behind interface:


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 Add_two_numbers
{
 
    public partial class Form1 : Form
    {
         public Form1()
        {
            InitializeComponent();
        }

        private void Add_button_Click(object sender, EventArgs e)
        {
            try
            {
                double a = Convert.ToDouble(textBox1.Text);
                double b = Convert.ToDouble(textBox2.Text);
                textBox3.Text = (a + b).ToString();
            }
            catch(Exception)
            {
                MessageBox.Show("invalid input");
            }
        }
    }
}

More C# programs here




3 comments: