Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,411 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 2,464 people online right now. Registration is fast and FREE... Join Now!




{0} Meaning

 
Reply to this topicStart new topic

{0} Meaning

gbertoli3
15 Oct, 2008 - 06:19 AM
Post #1

DIC at Heart + Code
Group Icon

Joined: 23 Jun, 2008
Posts: 1,046



Thanked: 17 times
Dream Kudos: 950
My Contributions
I have seen this a lot; like in:
csharp

Console.WriteLine("Line Number {0}" + linenumber);


What exactly is {0} used for?
User is offlineProfile CardPM
+Quote Post

baavgai
RE: {0} Meaning
15 Oct, 2008 - 07:05 AM
Post #2

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,024



Thanked: 105 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions
Your syntax is a hair off. It's probably clearer if you have more than one.

csharp

Console.WriteLine("row, col: {0},{1}", row, col);


This prints exactly the same thing:
csharp

Console.WriteLine("row, col: {1},{0}", col. row);


The {0} is a place holder for the first argument that follows, {1} is the next and so on. It's similar to %s or %d in C's printf, but it's not type specific unless you start using type modifiers.

User is online!Profile CardPM
+Quote Post

gbertoli3
RE: {0} Meaning
15 Oct, 2008 - 02:35 PM
Post #3

DIC at Heart + Code
Group Icon

Joined: 23 Jun, 2008
Posts: 1,046



Thanked: 17 times
Dream Kudos: 950
My Contributions
Oh Ok so it is basically for simplicity.

So you don't have to do:
csharp

MessageBox.Show("col: " + col + " row: " + row);

User is offlineProfile CardPM
+Quote Post

wingot
RE: {0} Meaning
15 Oct, 2008 - 03:42 PM
Post #4

New D.I.C Head
*

Joined: 13 Oct, 2008
Posts: 38

Yeah, exactly. It just makes the string easier to read since it is less broken up (in the same way that i++ is easier to read than i = i +1 in a for loop/in the middle of a block).
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 12:22PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month