-5

I have a situation where I would have to do the following -

String.Format("{0}",{1},"Hi!")

(This is just a very simple version of what i am trying to achieve)

And the output I want is -

Hi!

The output I am getting is -

{1}

String.Format("{0}","{1} Atul {2}","Hi!", "Kumar") I want the output to be - Hi Atul Kumar

  • 2
    @Steve That's what I thought at first, but it turns out it does compile - `{1}` is an array initialiser, the output is `"System.Int32[]"`. Still doesn't match what the OP claims the output is though... – James Thorpe Mar 23 '16 at 09:22

1 Answers1

6

String.Format is actually doing it's job perfectly. You pass "{1}" as the first format argument (I assume the {1} is within double quotes, or else the code won't produce the incorrect output you provided in your question). What you would instead want is to directly pass "Hi" as the first format argument:

String.Format("{0}, {1}", "Hi!", "<I think you want the user's name here>")

Seeing your comment below, you can use this:

String.Format("{0} {1} {2}", "Hi", "Atul", "Kumar");
Fᴀʀʜᴀɴ Aɴᴀᴍ
  • 6,131
  • 5
  • 31
  • 52