Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I want my textbox to write text + string

string a = "Morning"
textBox2.Text = ("Good {0}", a);


for an textbox output of "Good Morning" however it doesn't work

What I have tried:

but how come this on console application works

Console.WriteLine("temperature on Thursday is {0} degrees ", temperature);
Posted
Updated 12-May-18 16:29pm
v4

1 solution

Sigh...
C#
string a = "Morning";
textbox2.Text = string.Format("Good {0}", a);

The reason it works in WriteLine is because you're using an overload of WriteLine that specifically handles the string.Format() call for you.

That's not how string handling and assignments work though.

However, in newer versions of C#, you can do this:
C#
string a = "Morning";
textbox2.Text = $"Good {a}";
 
Share this answer
 
Comments
Afzaal Ahmad Zeeshan 13-May-18 7:22am    
5ed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900