-2

I want to use string interpolation for the below:

payloadArgs = string.Format("{0}TrackingID: \"{1}\"", payload.ToString().Replace("\n", "; "), trackingId);

I have tried

payloadArgs = $"{trackingId} TrackingId, \"{payload.ToString().Replace("\n", "; "), trackingId};

but I am obviously getting it wrong as I am getting a compile error "Cannot implicitly convert a string to int" over the "trackingId" and a warning about "newline in constant"

What's the correct way to do this?

Our Man in Bananas
  • 5,809
  • 21
  • 91
  • 148

1 Answers1

3

You are close. You changed the order between the variables, you had trackingId as the first variable instead as the second. In addition, string interpolation doesn't receive parameters in the structure of (string, parameter, parameter), it get it inside the curly brackets

payloadArgs = $"{payload.ToString().Replace("\n", "; ")}TrackingID: \"{trackingId}\"";
Guy
  • 46,488
  • 10
  • 44
  • 88