Hi, I wanted to know what does the ("{0}, {1}" signify in :

Console.WriteLine("{0}, {1}",
	    mixedCase,
	    lower);

Couldn't find it on google at all.


Thanks for everything!

{0} is the placeholder for the first argument after the format string, {1} is the second, and so on. For example, Console.WriteLine("{0}, {1}", "bleh", 53); would result in this line being written: bleh, 53 .

This is called composite formatting in .NET-land.

Here's another example:
Console.WriteLine("Hello, {0}, my name is {1}, "Bill", "Bob"); would print:

Hello, Bill, my name is Bob

when

Console.WriteLine("Hello, {1}, my name is {0}, "Bill", "Bob"); would print:

Hello, Bob, my name is Bill

Comments
agreed, explained well enough!
explained well with explanation

@gusano79
@emcoloney

thanks you both explained well , I understand what it does now!

Console.WriteLine("Hello, {0}, my name is {1}, "Bill", "Bob"); would print:

Actually it would print:

Error 1 Newline in constant
Error 2 ) expected
Error 3 ; expected
Error 4 ; expected
Error 5 ; expected
Error 6 ; expected

Console.WriteLine("Hello, {0}, my name is {1}, "Bill", "Bob"); would print:

Actually it would print:

Error 1 Newline in constant
Error 2 ) expected
Error 3 ; expected
Error 4 ; expected
Error 5 ; expected
Error 6 ; expected

Edited 5 Years Ago by Momerath: n/a

Numbers in brackets are placeholders (starting from 0 on). Values that you pass are showing instead of number and bracket together.
Example:

("{0}", myValue)

We can say its a stirng format, which you can use in the same form in Win forms:

MessageBox.Show(String.Format("{0}", myValue));
This article has been dead for over six months. Start a new discussion instead.