Reputation: 11
Here is my problem
I would like to have a label produce both the formula AND the answer.
Here is what I have...please help.
int score1
int score2
double addition
score1 = int.Parse(txbNumber1.Text);
score2 = int.Parse(txbNumber2.Text);
addition = score1 + score2;
lblAdditionResults.Text = addition.ToString();
Upvotes: 0
Views: 68
Reputation: 43
lblAdditionResults.Text = String.Format("{0} + {1} = {2}", score1, score2, addition);
Upvotes: 0
Reputation: 3013
Use String.Format
:
lblAdditionResults.Text = string.Format("{0} + {1} = {2}",score1,score2,addition)
Upvotes: 1
Reputation: 276286
Here is a C# 6 answer using template strings:
lblAdditionResults.Text = $"{addition} = {score1} + {score2}";
See the official guide about interpolated strings.
Upvotes: 1