It's not data
that is null
, but dataList
.
(不是data
为null
,而是dataList
。)
You need to create one with
(您需要创建一个)
public List<Object> dataList = new List<Object>();
Even better: since it's a field, make it private
.
(甚至更好:因为这是一个领域,所以将其private
。)
And if there's nothing preventing you, make it also readonly
. (如果没有什么阻止您,请将其设置为readonly
。)
Just good practice. (只是好的做法。)
Aside
(在旁边)
The correct way to check for nullity is if(data != null)
.
(检查无效性的正确方法是if(data != null)
。)
This kind of check is ubiquitous for reference types; (对于引用类型,这种检查无处不在。)
even Nullable<T>
overrides the equality operator to be a more convenient way of expressing nullable.HasValue
when checking for nullity. (即使Nullable<T>
覆盖相等运算符,也是检查nullable.HasValue
时表达nullable.HasValue
的更便捷方法。)
If you do if(!data.Equals(null))
then you will get a NullReferenceException
if data == null
.
(如果执行if(!data.Equals(null))
则如果data == null
则将收到NullReferenceException
。)
Which is kind of comical since avoiding this exception was the goal in the first place. (之所以有点可笑,是因为首先避免了此异常。)
You are also doing this:
(您也正在这样做:)
catch (Exception e)
{
throw new Exception(e.ToString());
}
This is definitely not good.
(这绝对不好。)
I can imagine that you put it there just so you can break into the debugger while still inside the method, in which case ignore this paragraph. (我可以想象您将其放在此处,以便可以在仍位于方法内部时进入调试器,在这种情况下,请忽略本段。)
Otherwise, don't catch exceptions for nothing. (否则,不要一无所获。)
And if you do, rethrow them using just throw;
(如果您这样做,则只需throw;
它们throw;
)
. (。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…