simple String formatting question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RichB

    #1

    simple String formatting question

    I am attempting to output a trace with details of the db id of a price
    using:

    Trace.WriteLine ("price id(first price): {0}",evnt.Price s[0].Id);

    Wher the Id is a string. I expect from this to output

    price id(first price): [priceid]

    instead I get:
    [priceid]: price id(first price):{0}

    Can anyone explain what is going wrong here. I have managed to fix this
    issue with the following:

    Trace.WriteLine (String.Format( "price id(first price):
    {0}",evnt.Price s[0].Id));

    But why does the string format incorrectly in the first instance?

    Thanks, Richard


  • Jon Skeet [C# MVP]

    #2
    Re: simple String formatting question

    On Aug 16, 10:56 am, "RichB" <ri...@communit y.nospamwrote:
    I am attempting to output a trace with details of the db id of a price
    using:
    >
    Trace.WriteLine ("price id(first price): {0}",evnt.Price s[0].Id);
    That call is to Trace.WriteLine (string, string). The first parameter
    is the message to write, and the second parameter is the category
    name. It's *not* a formatting call.

    Jon

    Comment

    • RichB

      #3
      Re: simple String formatting question

      Of course!!

      Thanks, Richard

      "Jon Skeet [C# MVP]" <skeet@pobox.co mwrote in message
      news:1187259111 .486520.144120@ r29g2000hsg.goo glegroups.com.. .
      On Aug 16, 10:56 am, "RichB" <ri...@communit y.nospamwrote:
      >I am attempting to output a trace with details of the db id of a price
      >using:
      >>
      >Trace.WriteLin e("price id(first price): {0}",evnt.Price s[0].Id);
      >
      That call is to Trace.WriteLine (string, string). The first parameter
      is the message to write, and the second parameter is the category
      name. It's *not* a formatting call.
      >
      Jon
      >

      Comment

      Working...