title: How to Convert Qt to C#
body: <p>I using this C++ code in Qt framework for convert hex to utf8, Now I want to use this into Visual Studio C#.   </p>
  
  <pre><code>QByteArray data = QByteArray::fromHex(ui-&gt;editorText-&gt;toPlainText().toUtf8());
  QString textData = QString::fromUtf8(data.constData(), data.size());
  </code></pre>
  
  <h2>What is equivalent of above code in C#?</h2>
  
  <p>Code:   </p>
  
  <pre><code>private void button1_Click(object sender, EventArgs e)
          {
              byte[] bytes = HexToBytes(textBox1.Text);
              textBox1.Text = Encoding.UTF8.GetString(bytes);
          }
  
  public static byte[] HexToBytes(string hex)
          {
              hex = hex.Trim();
  
              byte[] bytes = new byte[hex.Length / 2];
  
              for (int index = 0; index &lt; bytes.Length; index++)
              {
                  bytes[index] = byte.Parse(hex.Substring(index * 2, 2), NumberStyles.HexNumber);
              }
  
              return bytes;
          }
  </code></pre>