Hi,
Firstly, are you wanting to add int together, or double? or decimal?
I will base it on Double, (that way it will kinda do both)
public static double? ConvertToDouble(string p_dblToConvert)
{
try
{
return double.Parse(p_dblToConvert.Trim());
}
catch (Exception)
{
return null;
}
}
private static string AdditAndReturnIt(string p_no1, string p_no2)
{
double? no1conv = ConvertToDouble(p_no1);
double? no2conv = ConvertToDouble(p_no2);
if ((no1conv != null) & (no2conv != null))
{
return (no1conv + no2conv).ToString();
}
return "";
}
Using it, I just dragged 3 textboxes and a button to a form, and on button click event...
private void button1_Click(object sender, EventArgs e)
{
string no1 = textBox1.Text;
string no2 = textBox2.Text;
textBox3.Text = AdditAndReturnIt(no1, no2);
}
Hope this is what you were thinking
Good luck