Linked Questions
18 questions linked to/from Why use String.Format?
185
votes
32
answers
103k
views
String output: format or concat in C#?
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
In C# how do you use placeholders in Console.WriteLine()? [duplicate]
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 ...
0
votes
3
answers
218
views
Why string.format? [duplicate]
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);
0
votes
0
answers
564
views
Why would I use string interpolation in c#, since it's performes not as good as adding strings or variables? [duplicate]
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 ...
360
votes
18
answers
296k
views
Most efficient way to concatenate strings?
What's the most efficient way to concatenate strings?
101
votes
5
answers
93k
views
String.Join vs. StringBuilder: which is faster?
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?
30
votes
12
answers
64k
views
c# string formatting
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 ...
20
votes
8
answers
26k
views
Replace multiple words in string
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 ...
10
votes
5
answers
534
views
What is the difference between {0} and +?
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=" +...
15
votes
6
answers
5k
views
Performance issue: comparing to String.Format
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
Why use {} for printing out instead of the plus sign?
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 :" + ...
1
vote
5
answers
308
views
Formatting the output of a String
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 ...
0
votes
3
answers
182
views
Writing max array value to console window
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 ...
1
vote
7
answers
215
views
what is different between these to ways in writeline()? [duplicate]
Possible Duplicate:
C# String output: format or concat?
Console.WriteLine("Hi there, {0} {1}!", userName, userSurname);
Console.WriteLine("Hi there, " + userName + " " + userSurname + "!" );
i ...
0
votes
2
answers
1k
views
Use a while loop to insert into table
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.
"...