这是我的Linq查询:
result = From d In dc.Tracker
Where d.Responsible.Value = "first last name"
Order By d.Priority1, d.Deadline
Select New With { _
Key .Title = d.Name, _
Key .Description = d.Priority1, _
Key .Priority2= d.Priority2, _
Key .Status = d.Status, _
Key .Resp= d.Resp, _
Key .Deadline = d.Deadline, _
Key .Notes = d.Notes, _
}
我正在尝试输出数据,但似乎只能这样做:
For Each d In result
Console.WriteLine(d)
Next
但是我似乎无法将其放入数组中,以便我可以像这样调用它:
result(0), result(1), etc etc...
甚至更好:
result.Title, result.Description, etc etc...
如何将该 linq 更改为数组?
使用 .ToArray()
方法。
result = (From d In dc.Tracker
Where d.Responsible.Value = "first last name"
Order By d.Priority1, d.Deadline
Select New With { _
.Title = d.Name, _
.Description = d.Priority1, _
.Priority2= d.Priority2, _
.Status = d.Status, _
.Resp= d.Resp, _
.Deadline = d.Deadline, _
.Notes = d.Notes}).ToArray()
至少让它
按照我需要的方式工作:
Dim Title As New ArrayList
Dim Description As New ArrayList
Dim Priority2 As New ArrayList
Dim Status As New ArrayList
Dim Resp As New ArrayList
Dim Deadline As New ArrayList
Dim Notes As New ArrayList
result = From d In dc.Tracker
Where d.Responsible.Value = "first last name"
Order By d.Priority1, d.Deadline
Select New With { _
Key .Title = d.Name, _
Key .Description = d.Priority1, _
Key .Priority2= d.Priority2, _
Key .Status = d.Status, _
Key .Resp= d.Resp, _
Key .Deadline = d.Deadline, _
Key .Notes = d.Notes, _
}
For Each d In result
If Not IsNothing(d.Title()) Then Title.Add(d.Title()) Else Title.Add("NA")
If Not IsNothing(d.Description()) Then Description.Add(d.Description().value) Else Description.Add("NA")
If Not IsNothing(d.Priority2()) Then Cost.Add(d.Priority2().value) Else Priority2.Add("NA")
If Not IsNothing(d.Status()) Then Status.Add(d.Status().value) Else Status.Add("NA")
If Not IsNothing(d.Resp()) Then Responsible.Add(d.Resp().value) Else Resp.Add("NA")
If Not IsNothing(d.Deadline()) Then Deadline.Add(d.Deadline()) Else Deadline.Add("NA")
If Not IsNothing(d.Notes()) Then Notes.Add(d.Notes()) Else Notes.Add("NA")
Next