【发布时间】:2018-03-12 11:02:36
【问题描述】:
我有一个列表类型数组:
List<object>[] vector = new List<object>[3];
第一个 List 包含字符串:
// Get word lists together, remove duplicates
var words = tableA.ToList().Union(tableB.ToList());
// Sort words
words = words.OrderBy(s => s, StringComparer.CurrentCultureIgnoreCase);
// Add words to the vector first slot
vector[0] = words.ToList<object>();
现在,我想将整数添加到第二个和第三个列表中,但这里出现错误:
vector[1].Add(tableA.GetValue(keyword));
vector[2].Add(tableB.GetValue(keyword));
GetValue() 返回一个整数。但是当我将这些整数添加到向量列表中时,它会引发错误:
ERROR Caught: Object reference not set to an instance of an object.
我应该如何将整数添加到列表中?或者我应该使用其他一些数据结构来代替向量吗?我觉得我缺少一些琐碎的演员表,但我一直找不到解决方案。
【问题讨论】:
-
这东西还能编译吗?
-
是的,它已编译
-
List
-
哦,我在写问题时忘记了 []。列表[] 向量 = 新列表[3]; **
-
-3 代表你的 stackoverflow 的合法问题