String.Format()

When doing alot of string operations, you might want to consider using String.Format, instead of just concat'ing strings, as this example will show:

CodeSnippetExpression getSnippet = new CodeSnippetExpression("return " + "(" + type + ")this[\"" + FieldName + "\"]");

Might look acceptable, but this new line will look alot better, and be alot easier, since you wont be opening and closing strings left right and center:

CodeSnippetExpression getSnippet = new CodeSnippetExpression(String.Format("return ({0})this[\"{1}\"]",type,FieldName));

As you can see, all you need is the placeholders ({0} etc), then just list the parameters afterwards - its alot easier to read, plus you dont have to wonder if you have closed or opened the "'s properly... 

Leave a comment

Please be polite and on topic. Your e-mail will never be published.

Please add 4 and 2 and type the answer here: