var LocationList =   from Forms in Root.Descendants(Form)
                                        where 
                                        ( (string)Forms.Attribute(Id) == FormID  &&
                                          (string)Forms.Element(Control).Attribute(Id) == ControlID &&
                                          (string)Forms.Element(Control).Element(Layout).Attribute(direction) == Direction 
                                        )
                                        select new{
                                            X =(int)Forms.Element(Control).Element(Layout).Element(Location).Element(x),
                                            Y =(int)Forms.Element(Control).Element(Layout).Element(Location).Element(y),
                                            Width = (int)Forms.Element(Control).Element(Layout).Element(Size).Element(width),
                                            Height = (int)Forms.Element(Control).Element(Layout).Element(Size).Element(height),                                        };以上这句 怎么修改能变成返回一个值

解决方案 »

  1.   

    返回一组 x y width height 而不是多组
      

  2.   

    FirstOrDefault()  //找不到就返回null
    SingleOrDefault() //找到多个就报错 找不到就返回null
      

  3.   

    FirstOrDefault()  怎么加到以上的语句中
      

  4.   

    随便啊 LocationList.FirstOrDefault()就可以
    或者用这样的
    var LocationList =  Root.Descendants(Form).Where(a=>条件).FirstOrDefaut(b=>new{X=b.....Y=b....})