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!
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
@gusano79
@emcoloney
thanks you both explained well , I understand what it does now!
They are like %d or %f or %s of printf syntax in c or c++
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
@Momerath thanks for pointing that out
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));
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.