linq问题

moonshineidolon 2009-09-22 03:23:58
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),

};

以上这句 怎么修改能变成返回一个值
...全文
108 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Error_Code 2009-09-22
  • 打赏
  • 举报
回复
随便啊 LocationList.FirstOrDefault()就可以
或者用这样的
var LocationList = Root.Descendants(Form).Where(a=>条件).FirstOrDefaut(b=>new{X=b.....Y=b....})
moonshineidolon 2009-09-22
  • 打赏
  • 举报
回复
噢 知道了 谢谢
moonshineidolon 2009-09-22
  • 打赏
  • 举报
回复
FirstOrDefault() 怎么加到以上的语句中
Error_Code 2009-09-22
  • 打赏
  • 举报
回复
FirstOrDefault() //找不到就返回null
SingleOrDefault() //找到多个就报错 找不到就返回null
moonshineidolon 2009-09-22
  • 打赏
  • 举报
回复
返回一组 x y width height 而不是多组
Error_Code 2009-09-22
  • 打赏
  • 举报
回复
返回一个值是啥意思 你说的是单个引用还是单个值类型的值

111,097

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧