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.
public string GetMessage(params object[] otherValues)
{
return String.Format(this.Message, new[] { this.FirstValue }.Concat(otherValues).ToArray<object>());
}
You could use the Concat
and ToArray
extension methods:
public string GetMessage(params object[] otherValues)
{
var values = new[] { this.FirstName }.Concat(otherValues).ToArray();
return String.Format(this.Message, values);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With