Answer the question
In order to leave comments, you need to log in
C# code reduction?
Banal addition of 2 numbers
int a = Convert.ToInt32(textBox.Text);
int b = Convert.ToInt32(textBox1.Text);
label.Content = a + b;
Answer the question
In order to leave comments, you need to log in
label.Content = (Convert.ToInt32(textBox.Text) + Convert.ToInt32(textBox1.Text)).ToString();
private static string Sum(string a, string b)
{
return (Convert.ToInt32(a) + Convert.ToInt32(b)).ToString();
}
label.Content = Sum(textBox.Text, textBox1.Text);
label.Content = Sum(textBox.Text, textBox1.Text, textBox2.Text, textBox4.Text);
private static string Sum(params string[] n)
{
return n.Sum(itm => Convert.ToInt32(itm)).ToString();
}
public static class TextBoxExtension
{
public static string SumWith(this TextBox value, params TextBox[] n)
{
return (Convert.ToInt32(value.Text) + n.Sum(itm => Convert.ToInt32(itm.Text))).ToString();
}
}
public static class StringExtension
{
public static string SumWith(this string value, params string [] n)
{
return (Convert.ToInt32(value) + n.Sum(itm => Convert.ToInt32(itm))).ToString();
}
}
label.Content = textBox.Text.SumWith(textBox1.Text);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question