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