【问题标题】:GetByteCount shows up negative, but it's notGetByteCount 显示为负数,但事实并非如此
【发布时间】:2013-07-23 00:34:35
【问题描述】:

所以我试图从 litview 子项中获取 ByteCount,但它总是显示负面错误: [Argument OutOfRangeException 未处理:'count' 不能为负,参数名称:count] 这是我得到错误的代码行:

bw.Write(enc.GetBytes(listView1.Items[i].SubItems[3].Text + (new string('\0',dbytecnt - enc.GetByteCount(listView1.Items[i].SubItems[3].Text)))));

我试过这个:

 if (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)))));
                }

不起作用,甚至使if条件为'> -1',结果相同。

【问题讨论】:

    标签: c# winforms listview binarywriter


    【解决方案1】:

    例外是参数count 上的ArgumentOutOfRangeException。可能是字符串构造函数抛出了这个异常,而不是GetByteCount

    表示减法dbytecnt - enc.GetByteCount(listView1.Items[i].SubItems[3].Text)的结果是否定的。

    试试这个:

    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)))));
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-07
      • 1970-01-01
      • 2014-06-04
      • 2011-04-19
      • 2012-01-26
      • 1970-01-01
      • 2020-07-10
      • 2011-10-17
      相关资源
      最近更新 更多