String.Format() - Repassing params but adding more parameters

Luciano picture Luciano · May 8, 2012 · Viewed 11.1k times · Source

I would like to do something like that:

public string GetMessage(params object otherValues[]) {
    return String.Format(this.Message, this.FirstValue, otherValues);
}

So, I would like to repass an array of params to String.Format() but adding a new parameter.

What would be the best way to do that, knowing that we could "rebuild" a new array of objects and this doesn't seems good.

Answer

Tim S. picture Tim S. · May 8, 2012
public string GetMessage(params object[] otherValues)
{
    return String.Format(this.Message, new[] { this.FirstValue }.Concat(otherValues).ToArray<object>());
}