当usde linq Descendants()显示对象引用未设置为实例对象时 [英] when usde linq Descendants() shows object reference not set to an instance object

查看:72
本文介绍了当usde linq Descendants()显示对象引用未设置为实例对象时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当usde linq Descendants()显示对象引用未设置为实例对象时

未将对象引用设置到对象实例



代码如下:

when usde linq Descendants() shows object reference not set to an instance object
未将对象引用设置到对象实例

code as following:

IEnumerable<xelement> xelCls = from target in root.Elements()
                              where target.Attribute("Name").Value ==GetClsNameOfInstanse(lineNum - 1)
                              select target;







IEnumerable<xelement> xels = from target in xelCls.Descendants()
                              where target.Attribute("Name").Value == item
                              select target;



问题是第二个codenipt;错误是xels对象引用未设置为实例对象

未将对象引用设置到对象实例


the question is the second codesnipt ; the error is "xels" object reference not set to an instance object
未将对象引用设置到对象实例

推荐答案

试试这个:



Try this:

if (xelCls !=null && xelCls.Any())
{

IEnumerable<xelement> xels = from target in xelCls.Descendants()
                              where target.Attribute("Name").Value == item
                              select target;

}


if(xelCls!= null && xelCls.Any())

{



IEnumerable xels =来自xelCls.Descendants()中的目标

其中target.Attribute(Name)!= null && target.Attribute(名称)。值==项目

选择目标;

}
if (xelCls !=null && xelCls.Any())
{

IEnumerable xels = from target in xelCls.Descendants()
where target.Attribute("Name")!=null&&target.Attribute("Name").Value == item
select target;
}


这篇关于当usde linq Descendants()显示对象引用未设置为实例对象时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆