Search code examples
c#.netstring-formattingparams-keyword

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


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.


Solution

  • public string GetMessage(params object[] otherValues)
    {
        return String.Format(this.Message, new[] { this.FirstValue }.Concat(otherValues).ToArray<object>());
    }