Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# String.Format args

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 :)

like image 524
Fabio Milheiro Avatar asked Sep 16 '09 16:09

Fabio Milheiro


1 Answers

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); 
like image 111
csharptest.net Avatar answered Oct 15 '22 10:10

csharptest.net