String.Format
for simple concatenation. That's not what it's for, folks! String.Format
is to allow formatting (not just conversion to String
) and parameter rearrangement. Code like this is wasteful and silly:private string CreateSelect() { return String.Format("SELECT TOP {0} {1} FROM {2}", this.rowLimit, this.selectFields, this.fromTables); }This will needlessly have to scan the format string looking for the replacement parameters
{x}
and substituting the parameters positionally. This code should be:private string CreateSelect() { return "SELECT TOP " + this.rowLimit + " " + this.selectFields + " FROM " + this.fromTables; }Which C# will actually turn into this behind the scenes:
private string CreateSelect() { String[] temp = new String[6] { "SELECT TOP ", this.rowLimit.ToString(), " ", this.selectFields, " FROM ", this.fromTables }; return String.Concat(temp); }Which is tons faster. This sort of thing is important to get right in the lowest-level of your code, in things like a DAL or UI framework library.
Not that I'm whining...