#16 – Use an Array of Objects for a Composite Format String

Instead of passing in a long list of format items when calling a method like String.Format that deals with composite format strings,  you can also just pass in an array of objects.  Here’s an example:

object[] args = { "Sean", 36, "Sexton", "C#" };
string sTest = string.Format("{0} {2} has been programming for {1} yrs and loves {3}.", args);

The resulting string here would be:  Sean Sexton has been programming for 36 yrs and loves C#.

Advertisements

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: