user613326
user613326

Reputation: 2180

Console.WriteLine conversion to string

In Csharp its normal to write to the console like below, i am translating an old console app to a gui based application and now i wonder if this can be turned simply in strings; so i can do a quick rename, of console.Writeline

    var p = new { FirstName = "Bill", LastName = "Gates" };

    Console.WriteLine("Fristname {0} Lastname {1}", p.FirstName, p.LastName);

I want something like that, i'll like to keep using that format, but turn it to a normal string so you get

     tbTextBox1.text = tbTextBox1.text + ("Fristname {0} Lastname {1}", p.FirstName, p.LastName)

Is there a simple string conversion function for that ?

I know i could write it like below but if there is a simple conversion i would prefer that

     tbTextbox1.text= "Firstname " + p.Firstname + " Lastname " + p.lastname;

Upvotes: 0

Views: 962

Answers (2)

Aamir Waheed
Aamir Waheed

Reputation: 459

You can try this

tbTextBox1.text += String.Format("Fristname {0} Lastname {1}", p.FirstName, p.LastName)

Upvotes: 1

SLaks
SLaks

Reputation: 887451

You're looking for String.Format(), which does exactly that.

Upvotes: 0

Related Questions