String.Format is just so cool. It makes your code less spaghetti like and makes it easier to replace string values or add new values. It also allows you to see from a quick glance what your code does. It also makes it MUCH easier to update your string and add more parameters to it. It works similarly to the printf function in C++ that takes a string, and then is followed by parameters that specify what to plug into the string.
Here is a String.Format example (C#):
text1.Text = string.Format("<a href=\"Mylink.aspx?abc=0&Color={0}\">my Link text</a>", myColor);
Isn’t that much nicer than our not so clean string concatenation (C#):
text1.Text = "<a href=\"Mylink.aspx?abc=0&Color=" + myColor + "\">my Link text</a>";
Now if we want to add one more parameter, it’s still so clean! Note that it is the same syntax for C# and VB.NET
text1.Text = string.Format("<a href=\"Mylink.aspx?abc=0&ID={0}&wl={1}\">my Link text</a>", myColor, myWeight);
However, there are some performance considerations to think about. In most cases, the minor performance gain is negligible compared to the clarity of code benefits.


