Blog

Subtract Two Numbers without using - Operator

Posted by Satyapriya Nayak Blogs | Windows Forms C# Dec 18, 2012
In this blog, we will know how to subtract two numbers without using - operator.

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 = "";
        }
    }


COMMENT USING
PREMIUM SPONSORS
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.
Employers - Post Free Jobs
SPONSORED BY
  • MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.
Employers - Post Free Jobs