#973 – Format Items in Composite Format Strings Can Be in Any Order

A composite format string contains some combination of actual text and format items that will be substituted with values of corresponding placeholders at run-time.

For example:

            string name = "Sean";
            int age = 49;

            Console.WriteLine(string.Format("{0} is {1} yrs old. {0} is old.", name, age));


A format item is indicated by a 0-based index within a pair of braces. Notice that you can have multiple format items that refer to the same placeholder.

You can also include the format items in any order.  At run-time, each format item is evaluated and the appropriate value is substituted.

            Console.WriteLine(string.Format("Age: {1}, Name: {0}.  {1} {1} {1}..", name, age));



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

One Response to #973 – Format Items in Composite Format Strings Can Be in Any Order

  1. Pingback: Dew Drop – November 13, 2013 (#1666) | Morning Dew

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 )

Facebook photo

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

Connecting to %s

%d bloggers like this: