Preprocess Message
If you don't want a creation of a new array in every GetMessage(...) call you can insert FirstValue into Message at the beginning once a time. And then GetMessage(...) just uses the otherValues parameter for string.Format(...).
The Message property is initialized once after FirstValue is set, e.g. in constructor or in an init method like so:
void InitMessage()
{
Message = String.Format(Message, FirstValue, "{0}", "{1}", "{2}", "{3}", "{4}");
}
The InitMessage method initializes first index in Message with FirstValue and the rest of indexes with "{index}", i.e. "{0}", "{1}", "{2}",... (It is allowed to have more params
elements than message indexes).
Now GetMessage can call String.Format without any array operations like so:
public string GetMessage(params object[] otherValues)
{
return String.Format(Message, otherValues);
}
Example:
Assume following property values:
this.Message = "First value is '{0}'. Other values are '{1}' and '{2}'."
and this.FirstValue = "blue"
.
InitMessage changes Message to:
"First value is 'blue'. Other values are '{0}' and '{1}'."
.
GetMessage call
GetMessage("green", "red")
results in
"First value is 'blue'. Other values are 'green' and 'red'."
.
ToArray()
builds a new structure. – Oniskey