I have an array like this:
object[] args
and need to insert those args in a string, for example:
str = String.Format("Her name is {0} and she's {1} years old", args);
instead of:
str = String.Format("Her name is {0} and she's {1} years old", args[0], args[1]);
NOTE: Actually the first line of code worked! But args[1] was missing! Sorry and thank you. Points for every one :)
Your first example should work fine, provided there are at least two objects in the array args.
object[] args = new object[] { "Alice", 2 }; str = String.Format("Her name is {0} and she's {1} years old", args);
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