c# - NullException:值不能未定义。参数名称:来源
问题描述
//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 < length) 上显示,但它在
string[] onlyInterestingParts = entries
.TakeHorizontalSlice((uint)x)
.Take(4)
.ToArray();
TakeHorizontalSlice((uint)x) 返回 null
推荐阅读
- php - 如何逐行读取和更新表格sql和php?
- javascript - Node express 服务器仅对 localhost 使用中间件
- c# - Xamarin.Forms 内存泄漏;GC 没有收集所有东西
- r - 如何在R中为一次一个逻辑回归制作循环?
- python - 在python中查找可以由字符串组成的单词
- java - 如何将图像和文档同时上传到 Firebase 存储,获取下载 URL 并将它们同时插入实时数据库?
- jquery - 使用 AJAX 调用从 API 获取数据的变量
- date - Power BI 汇率计算
- python - 如何根据我的代码输出在 jupyter notebook 中创建文本文件
- php - 在 PHP 中加入多个 json 文件的最有效方法