title: Failing to use String.Format in C#
body: <p>I am a C++ developer and shifted to wpf last week. Well I have used sprintf in my c++ apps many time and now I have across the need of having something equivalent to that in C#. Here is what I had done is C++:</p>
  
  <pre><code>char t_str[4] = {};
  for(int i = 0; i &lt; 4; i++)
  { 
      sprintf(t_str, "%02X", buffer[i]);
  m_apiResponse[i]-&gt;setText(String(t_str));
  }
  </code></pre>
  
  <p>where <code>buffer[0] = 20;
                  buffer[1] = 30;
                  buffer[2] = 40;
                  buffer[3] = 50;</code> and <code>m_apiResponse</code> is a textbox.</p>
  
  <p>I had done this in my C# as follows:</p>
  
  <pre><code>Byte[] t_str = new Byte[4];
  for (int i = 0; i &lt; 4; i++)
  {
           string bufstring = String.Format("{0:02}", buffer[i]);
           t_str = Encoding.UTF8.GetBytes(bufstring);
  }
  
  Response1Box = Convert.ToString(t_str[0]);
  Response2Box = Convert.ToString(t_str[1]);
  Response3Box = Convert.ToString(t_str[2]);
  Response4Box = Convert.ToString(t_str[3]);
  </code></pre>
  
  <p>where ResposeBox is a textbox which I have bind to:</p>
  
  <pre><code>// Description of Response1Box
      private string _Response1Box;
      public string Response1Box
      {
          get
          {
              return _Response1Box;
          }
  
          set
          {
              _Response1Box = value;
              OnPropertyChanged("Response1Box");
          }
      }
  </code></pre>
  
  <p><code>buffer[64]</code> is byte[]. </p>
  
  <p>Its not giving me the expected answer which my C++ method does. Is this the right way to do: <code>string bufstring = String.Format("{0:02}", buffer[i]);
               t_str = Encoding.UTF8.GetBytes(bufstring);</code> Where am i wrong???</p>
  
  <p>Please help :)</p>