我有以下代码:
try
{
var result =
from entry in feed.Descendants(a + "entry")
let content = entry.Element(a + "content")
let properties = content.Element(m + "properties")
let notes = properties.Element(d + "DetailsJSON")
let questionMessage = properties.Element(d + "QuestionText")
let title = properties.Element(d + "Title")
let partitionKey = properties.Element(d + "PartitionKey")
where partitionKey.Value == "0001I" && title != null
select new Question
{
Notes = notes.Value ?? "n/a",
Title = title.Value,
QuestionMessage = questionMessage.Value
};
// xx
IList<Question> resultx = null;
foreach (var question in result)
{
resultx.Add(question);
}
// yy
return result;
}
catch (Exception ex)
{
throw new InvalidOperationException("GetQuestions.Get problem", ex);
};
如果我注释掉 xx 和 yy 之间的代码部分,那么它就可以工作。否则我得到一个例外说:
ex {"Object reference not set to an instance of an object."} System.Exception {System.NullReferenceException}
有人可以给我一些关于我可能做错了什么的想法吗?