String.Format extension method
c#, coding-style, extension-methods
Solution
Well, one bad thing there is that by only having a single `params object[]` method you force an extra array allocation per-call.
You may notice that `string.Format` has a range of overloads for taking low numbers of arguments (these are very commonly used) - I would suggest duplicating them.
Your "ideal" scenario could be done by re-writing the `string.Format` method, but you'd need to pass in the values, i.e.
return "date: {date}\ntime: {...}\nuser: {_user} ({_status})"
.Format(new { date = DateTime.Now, _user, _status });
(and using your own custom `Format` method, or one like this) - but note this forces a new object instance per call.
Actually, at one point the mono compiler had an experimental flag to enable this directly. I don't know if it is maintained.
Problem
I have: ``` public static string Format(this string text, params object[] args) { return string.Format(text, args); } ``` So I can do: ``` "blablabla {0}".Format(variable1); ``` Is it a good/bad? Can it become even shorter? I want to have strings build seamlessly, like writing the text without worrying before or after of parameters and stuff: ``` // bad return "date: " + DateTime.Now.ToString("dd.MM.yyyy") + "\ntime: " + DateTime.Now.ToString("mm:HH:ss") + "\nuser: " + _user + " (" + _status + ")"; // better, but you have to deal with order of {0}...{n} and order of parameters return string.Format("date: {0}\ntime: {1}\user: {2} ({3})", ...); // ideal return "date: {DateTime.Now{dd:MM:yyyy}}\ntime: {...}\nuser: {_user} ({_status})"; ```