日期:2014-05-17  浏览次数:21098 次

请教c#与vb.net互相转换问题
现在需要把一段c#代码转为vb.net,请教,谢谢。
 
   
  var query = from g in document.Elements("group")
  select new
  {
  Title = g.Attribute("title") != null ? g.Attribute("title").Value : "",
  Items = (from i in g.Elements("item")
  select new
  {
  Title = i.Element("title") != null ? i.Element("title").Value : "",
  Icon = i.Element("item-icon") != null ? i.Element("item-icon").Value : defaultIcon,
  Id = i.Element("id") != null ? i.Element("id").Value : ""
  }
  )
  };


------解决方案--------------------
Dim query = From g In document.Elements("group")
Select New With {
.Title = If(g.Attribute("title") IsNot Nothing, g.Attribute("title").Value, ""),
.Items = (From i In g.Elements("item")
Select New With
{
.Title = If(i.Element("title") IsNot Nothing, i.Element("title").Value, ""),
.Icon = If(i.Element("item-icon") IsNot Nothing, i.Element("item-icon").Value, defaulticon),
.Id = If(i.Element("id") IsNot Nothing, i.Element("id").Value, "")
})
}