The exception is an ArgumentOutOfRangeException
on parameter count
. It's probably the string constructor which throws this exception, not GetByteCount
.
It means that the result of the subtraction dbytecnt - enc.GetByteCount(listView1.Items[i].SubItems[3].Text)
is negative.
Try this:
if (dbytecnt - enc.GetByteCount(listView1.Items[i].SubItems[3].Text) > 0)
{
bw.Write(enc.GetBytes(listView1.Items[i].SubItems[3].Text + (new string('\0',dbytecnt - enc.GetByteCount(listView1.Items[i].SubItems[3].Text)))));
}