Click here to Skip to main content
14,271,891 members
Rate this:
Please Sign up or sign in to 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

Rate this:
Please Sign up or sign in to vote.

Solution 1

Sigh...
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:
string a = "Morning";
textbox2.Text = $"Good {a}";
   
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100