Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 引用第一个子对象和获取对象引用错误_C# - Fatal编程技术网

C# 引用第一个子对象和获取对象引用错误

C# 引用第一个子对象和获取对象引用错误,c#,C#,我可以返回两个不同的XML响应。它们看起来像这样: 1) 如果没有用户,则返回 <ArrayUser xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> 我的问题是,如果未返回用户,则会在if语句中出现错误,并且对象引用未设置为对象错误的实例。仅当返回带有用户信息的数字2时,如何进入if语句 谢谢 if(userLookupResponse.DocumentElement.FirstChild.Name.Equals(“用户”)

我可以返回两个不同的XML响应。它们看起来像这样:

1) 如果没有用户,则返回

<ArrayUser xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
我的问题是,如果未返回用户,则会在
if
语句中出现错误,并且对象引用未设置为对象错误的实例。仅当返回带有用户信息的数字2时,如何进入if语句

谢谢

if(userLookupResponse.DocumentElement.FirstChild.Name.Equals(“用户”))

我猜FirstChild将是空的,因为没有child

为什么不改变你的测试,看看:

if(userLookupResponse.DocumentElement.FirstChild!=null)

if(userLookupResponse.DocumentElement.FirstChild.Name.Equals(“用户”))

我猜FirstChild将是空的,因为没有child

为什么不改变你的测试,看看:

if(userLookupResponse.DocumentElement.FirstChild!=null)


是的,成功了。我正在尝试
userLookupResponse!=空
。谢谢你的帮助。是的,这很有效。我正在尝试
userLookupResponse!=空
。谢谢你的帮助。
<ArrayUser xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <User>
    <Name></Name>
    <ID></ID>
  </User>
        if (userLookupResponse.DocumentElement.FirstChild.Name.Equals("User")) 
        {
            XmlNamespaceManager nsm = addXmlNamespaces(userLookupResponse);
            userLookupResponse.LoadXml(userLookupResponse.SelectSingleNode("//SSO:User", nsm).OuterXml);
            return userLookupResponse;
        }