Ultra Newbie Question

  • Thread starter Thread starter Pross
  • Start date Start date
P

Pross

I apologize for asking what is probably a real silly question but I am not a
C# programmer. I work in VB but a lot of code examples are in C# and I am
trying to translate some code and I don;t understand what this syntax means:

//------------------------------------------------------------------------------------------------
private void blah()
{
PopHandler foo = new PopHandler("YourServer",110,"YourName","YourPass");
string[] list = foo.GetList();
for (int i = 0; i< list.Length; i++)
{
Console.WriteLine("Getting Mail {0}: {1}",i+1,list);
PopMail Mail = foo.GetMail(i);
Console.WriteLine(@"Sender: {0}
Subject: {1}
Number of Parts:
{2}",Mail[0]["From"],Mail[0]["Subject"],Mail.ParagraphCount);
for (int a = 1; a < Mail.ParagraphCount; a++)
//------------------------------------------------------------------------------------------------

In that code snippit what is the {0}, {1}, and {2}? I hope I've included
enough information .

Paul Ross
 
Paul,

There is an overload of the WriteLine method which will take a format
string (the string with the "{0}", "{1}", and "{2}"), as well as values, and
insert those values into the string at those positions. If you notice,
there are three parameters. The first will be inserted into the string at
{0} (since it is zero-based), then second at {1}, and so on, and so on.

The static Format method on the String class will do the same thing
(returning a string), as well as the AppendFormat method on the
StringBuilder class.

Hope this helps.
 
If I understand you right:

string test1 = "Test One"
string test2 = "Test Two"
Console.WriteLine("Insert first string here - {0}: Insert second string
here - {1}", test1,test2);

should output:

Insert first string here - Test One: Insert second string here - Test Two

Paul


Nicholas Paldino said:
Paul,

There is an overload of the WriteLine method which will take a format
string (the string with the "{0}", "{1}", and "{2}"), as well as values,
and insert those values into the string at those positions. If you
notice, there are three parameters. The first will be inserted into the
string at {0} (since it is zero-based), then second at {1}, and so on, and
so on.

The static Format method on the String class will do the same thing
(returning a string), as well as the AppendFormat method on the
StringBuilder class.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Pross said:
I apologize for asking what is probably a real silly question but I am not
a C# programmer. I work in VB but a lot of code examples are in C# and I
am trying to translate some code and I don;t understand what this syntax
means:

//------------------------------------------------------------------------------------------------
private void blah()
{
PopHandler foo = new
PopHandler("YourServer",110,"YourName","YourPass");
string[] list = foo.GetList();
for (int i = 0; i< list.Length; i++)
{
Console.WriteLine("Getting Mail {0}: {1}",i+1,list);
PopMail Mail = foo.GetMail(i);
Console.WriteLine(@"Sender: {0}
Subject: {1}
Number of Parts:
{2}",Mail[0]["From"],Mail[0]["Subject"],Mail.ParagraphCount);
for (int a = 1; a < Mail.ParagraphCount; a++)
//------------------------------------------------------------------------------------------------

In that code snippit what is the {0}, {1}, and {2}? I hope I've included
enough information .

Paul Ross

 
Pross said:
string test1 = "Test One"
string test2 = "Test Two"
Console.WriteLine("Insert first string here - {0}: Insert second
string here - {1}", test1,test2);

should output:

Insert first string here - Test One: Insert second string here - Test
Two

Yes exactly.


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Get your ASP.NET in gear with IntraWeb!
http://www.atozed.com/IntraWeb/
 
Back
Top