【问题标题】:NullException: Value cannot be undefined. Parameter name: sourceNullException:值不能未定义。参数名称:来源
【发布时间】:2019-11-28 09:25:00
【问题描述】:
        //get entries
        string[,] entries = Search(ReplaceBlankWithAny(
          new string[] { name, code, supplier, lot, grams, date, shelf, inStock, costKG }), 
          data);

        int length = entries.GetLength(0);
        int x = 0;

        if (entries.GetLength(1) != 0)
        {
            x = 0;
            //populate table
            //for (uint x = 0; x < entries.GetLength(0); x++) not working
            while (x < length)
            {
                string[] onlyInterestingParts = entries
                  .TakeHorizontalSlice((uint)x)
                  .Take(4)
                  .ToArray();

                Main.instance.dataGridViewMatPrime.Rows.Add(onlyInterestingParts);

                x++;
            }
        }

        return entries;

我尝试使用 for(在代码中注释),然后使用了一段时间,但它们都在标题中返回错误。我将变量 x 移到 if 之外,但它仍然不起作用。我确信 ENTRIES IS NOT NULL,既因为 if (entries.GetLength(1) != 0) 为真,又因为我在调试器中检查了它。任何回复都非常感谢!

【问题讨论】:

  • 异常发生在哪一行?
  • 发生在 while (x

标签: c# winforms for-loop while-loop null


【解决方案1】:

问题在 while (x

string[] onlyInterestingParts = entries
                  .TakeHorizontalSlice((uint)x)
                  .Take(4)
                  .ToArray();

TakeHorizo​​ntalSlice((uint)x) 返回 null

【讨论】:

    猜你喜欢
    • 2013-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-12
    • 2020-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多