String.Format changes code from looking like this (in VB.NET):
Dim MyString as String = _
"Value of " & MyVariableName & " equals " & _
MyVariableValue & "."
To looking like this:
Dim MyString as String = _
String.Format("Value of {0} equals {1}.", _
MyVariableName, MyVariableValue)
Let's look at the differences. First, the String.Format route is much more readable. It is pretty clear what the result of the concatenation will be without needing to understand the code. Second, the String.Format approach is significantly less error prone--no more have to recompile because you missed an ampersand, quote, etc.
Plus, your coworkers will thank you. Whoever needs to read or maintain your code after you will save time and be able to make changes more easily. Plus, they may pick up the important skill of using String.Format....
0 comments:
Post a Comment