执行一个查询每次都能返回一个string[] 数组 但是数组的大小都不确定,有什么好的建议 目前先用object 顶一下
 
object value =(
                    from entry in nodes.Cast<HtmlNode>()
                    let Name = entry.Attributes["name"]
                    let Content = entry.Attributes["content"]
                    where Name != null && !string.IsNullOrEmpty(Name.Value) && Content != null && !string.IsNullOrEmpty(Content.Value)
                    select Name.Value + ": " + Content.Value).ToArray();

解决方案 »

  1.   

    不明白你想表达什么意思
    var value =(
                        from entry in nodes.Cast<HtmlNode>()
                        let Name = entry.Attributes["name"]
                        let Content = entry.Attributes["content"]
                        where Name != null && !string.IsNullOrEmpty(Name.Value) && Content != null && !string.IsNullOrEmpty(Content.Value)
                        select Name.Value + ": " + Content.Value).ToList();
      

  2.   

    或者你也可以定义一个 临时类:
    class temp
    {
      public String Name{get;set;}
    }
    List<temp> value =(
      from entry in nodes.Cast<HtmlNode>()
      let Name = entry.Attributes["name"]
      let Content = entry.Attributes["content"]
      where Name != null && !string.IsNullOrEmpty(Name.Value) && Content != null && !string.IsNullOrEmpty(Content.Value)
      select new temp{Name=Name.Value + ": " + Content.Value}).ToList();
      

  3.   

    你可以找一个特殊字符 作为分隔符 如: $
    string result=string.Join("$",(from entry in nodes.Cast<HtmlNode>()
                        let Name = entry.Attributes["name"]
                        let Content = entry.Attributes["content"]
                        where Name != null && !string.IsNullOrEmpty(Name.Value) && Content != null && !string.IsNullOrEmpty(Content.Value)
                        select Name.Value + ": " + Content.Value).ToArray());从库里取出再Split('$') 转成string[]