Linked Questions

185 votes
32 answers
103k views

Let's say that you want to output or concat strings. Which of the following styles do you prefer? var p = new { FirstName = "Bill", LastName = "Gates" }; Console.WriteLine("{0} {1}", p.FirstName, p....
4 votes
3 answers
33k views

Am I using the {0} and {1} correctly in the code below for the name variable and age variable? What are the {0} and {1} called, are they formally called "placeholders"? Is it more preferable to use ...
shampouya's user avatar
  • 416
0 votes
3 answers
218 views

Why shouldn't we simply use string s=product.Name+" has been saved"; instead of: string s=string.Format("{0} has been saved", product.Name);
Aparan's user avatar
  • 1,283
0 votes
0 answers
564 views

So yesterday I saw this tutorial on c# and I learned about string interpolation. I've always programmed in java and just used the + to add strings. Now I'm trying to find out why you would use ...
Foitn's user avatar
  • 786
360 votes
18 answers
296k views

What's the most efficient way to concatenate strings?
jimmij's user avatar
  • 3,651
101 votes
5 answers
93k views

In a previous question about formatting a double[][] to CSV format, it was suggested that using StringBuilder would be faster than String.Join. Is this true?
Hosam Aly's user avatar
  • 42.6k
30 votes
12 answers
64k views

I m curious why would i use string formatting while i can use concatenation such as Console.WriteLine("Hello {0} !", name); Console.WriteLine("Hello "+ name + " !"); Why to prefer the first one over ...
DarthVader's user avatar
  • 55.6k
20 votes
8 answers
26k views

I have multiple words I want to replace with values, whats the best way to do this? Example: This is what I have done but it feels and looks so wrong string s ="Dear <Name>, your booking is ...
David's user avatar
  • 1,455
10 votes
5 answers
534 views

Is there any difference between the use of {0} and + as they both are doing the same work of printing the length on the screen: Console.WriteLine("Length={0}", length); Console.WriteLine("Length=" +...
AK1's user avatar
  • 123
15 votes
6 answers
5k views

A while back a post by Jon Skeet planted the idea in my head of building a CompiledFormatter class, for using in a loop instead of String.Format() and similar. The idea is the portion of a call to ...
2 votes
5 answers
364 views

I am coding in Unity3D in C#, and when printing or using debug statements or console statements, I have always used something like this: Debug.Log("The sum of these two variables is :" + ...
Mike Davis's user avatar
1 vote
5 answers
308 views

I am new to C#. I am studying it in a module in college. We have been given an assignment which involves us having to create a simple booking application using the various components included in the ...
Javacadabra's user avatar
  • 5,778
0 votes
3 answers
182 views

I am sure there is something stupid i am missing. I want to print the message to console window and in the same line show the max array value. When i run the code without the console message it runs ...
Timothy Goodes's user avatar
1 vote
7 answers
215 views

Possible Duplicate: C# String output: format or concat? Console.WriteLine("Hi there, {0} {1}!", userName, userSurname); Console.WriteLine("Hi there, " + userName + " " + userSurname + "!" ); i ...
Masoud Darvishian's user avatar
0 votes
2 answers
1k views

I'm trying to use a while loop to insert into a table from a List. I want to loop through and write each item from the list by it's index. I'm getting an error with the values I'm trying to insert. "...
B Minster's user avatar
  • 341

15 30 50 per page