Subtract Two Numbers without using - Operator

By Satyapriya Nayak Dec 18, 2012
In this blog, we will know how to subtract two numbers without using - operator.
Download Files: Subtract two numbers

In this blog, we will know how to subtract two numbers without using - operator.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Subtract_two_numbers_without_minus
{
     public partial class Form1 : Form
    {
        public Form1()
        {
             InitializeComponent();
        }
        private void btn_Subtract_Click(object sender, EventArgs e)
        {
            int value1, value2, difference;
            if (!int.TryParse(textBox1.Text, out value1))
            {
                MessageBox.Show("Not a valid integer. Please re-enter.");
                 textBox1.Focus();
                return;
            }
            if (!int.TryParse(textBox2.Text, out value2))
            {
                MessageBox.Show("Not a valid integer. Please re-enter.");
                 textBox2.Focus();
                return;
            }
            difference = value1 + ~value2 + 1;
            MessageBox.Show(difference.ToString());
            clear();
        }
        void clear()
        {
            textBox1.Text = "";
            textBox2.Text = "";
        }
    }


Satyapriya Nayak

Satyapriya Nayak is a software developer from Bhubaneswar, India. He holds a Bachelor's degree in Electronics and telecommunication and is an active member of C# Corner. 

COMMENT USING

PREMIUM SPONSORS

Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.

Latest Blogs