Reputation: 719
I have a form with a button that adds the values of multiple labels(that are filled with currency values) and displays the sum in another label.
decimal[] totals = new decimal[11];
private void calculate_Click(object sender, EventArgs e)
{
totals[0] = decimal.Parse(lblText1.Text, NumberStyles.Currency);
totals[1] = decimal.Parse(lbltext2.Text, NumberStyles.Currency);
lbltotal.Text = totals.Sum().ToString("C");
}
Works fine until one is empty and I get 'input string not in a correct format'.
Upvotes: 0
Views: 317
Reputation: 6689
Upvotes: 1