문제

아래의 vb.net 구문은 무엇입니까?

   var list = xd.Descendants("product")
   .Select(element =>new 
   { 
      Title = element.Attribute("title").Value,                   
      Duration = element.Element("duration").Value 
   }).ToList(); 
도움이 되었습니까?

해결책

이 시도:

Dim list = 
   From element In xd.Descendants("product")
   Select New With { _ 
       .Title = element.Attribute("title").Value, _
       .Duration = element.Element("duration").Value }

LINQ 구문을 사용할 필요가 없으며 기본 확장 만 사용할 수 있습니다.

Dim list = xd.Descendants("product"). _
    Select(Function(element) _ 
        New With { _ 
           .Title = element.Attribute("title").Value, _
           .Duration = element.Element("duration").Value _
        }). _
    ToList()

다른 팁

VB를 사용하는 경우 이에 대한 구문 설탕이 있습니다.

Dim list = 
   From element In xd...<product>
   Select New With { _ 
       .Title = element.@title, _
       .Duration = element.<duration>.Value }

좋은 점은 문서에 대한 XSD가있는 경우 (하나 또는 여러 XML 문서에서 유추하여 Visual Studio를 통해 하나를 만들 수 있음) 네임 스페이스와 비주얼 스튜디오가 제공 할 수있는 것처럼 거의 가져올 수 있다는 것입니다. 쿼리를 작성할 때 Intellisense 완료.

일부 참조 :

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top