title: Error While Converting Byte array to string in this algorithm
body: <p>I want to read a file using <code>File.Readallbytes(myfile)</code> and to convert it to String like</p>
  
  <pre><code>string s=ByteArraytoString(File.Readallbytes(myfile));
  </code></pre>
  
  <p>but it doesn't really works for every file i choose, instead when the file is unicode it works file otherwise it doesn't ,so if any one can help me in this</p>
  
  <pre><code> public static string ByteArrayToString(byte[] bytes)
          {
              char[] chars = new char[(bytes.Length / sizeof(char))];
              Buffer.BlockCopy(bytes, 0, chars, 0, bytes.Length);
              return new string(chars);
          }
          public static byte[] StringToByteArray(string s)
          {
              byte[] bytes = new byte[s.Length * sizeof(char)];
              Buffer.BlockCopy(s.ToCharArray(), 0, bytes, 0, bytes.Length);
              return bytes;
          }
  </code></pre>
  
  <p><em>so the exception is</em>: in <strong>ByteArrayToString</strong> method</p>
  
  <blockquote>
    <p>System.ArgumentException: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
       at System.Buffer.BlockCopy(Array src, Int32 srcOffset, Array dst, Int32 dstOffset, Int32 count)</p>
  </blockquote>
  
  <p>i know this soloution posted like 1000 time but no one fix this problem in this code</p>