Мне понадобится:
a list(of employee)
, который содержит всех сотрудников всех компаний.(e1, e2 ... e9)
у сотрудника, у которого самая старая DischargeDate более 1 января 2008 года
Я решилэто таким образом, но я думаю, что это может быть достигнуто более ясным и эффективным способом.Может быть, используя Linq или / и некоторые лямбда-выражения
1:
Dim allEmp As New List(Of employee)
For Each co In Comps
For Each emplo In co.emp
allEmp.Add(emplo)
Next
Next
2:
Dim min As Date = Nothing
For Each c In Comps
For Each em In c.emp
If min = Nothing OrElse (em.DischargeDate > New Date(2018, 1, 1) AndAlso em.DischargeDate < min) Then
min = em.DischargeDate
End If
Next
Next
Я также пытался
Dim xxx As List(Of List(Of employee)) = Comps.Select(Function(j) j.emp).ToList
Но таким образом я получаю List(Of List(Of employee))
вместо List(Of employee)
это классы
Public Class company
Public name As String
Public emp As List(Of employee)
End Class
Public Class employee
Public name As String
Public email As String
Public DischargeDate As Date
End Class
А вот коллекции
Private Comps As New List(Of company)
Dim e As List(Of employee)
Dim e1 As New employee With {.email = "aaa@aaa.aaa", .name = "nameEmp1", .DischargeDate = New Date(2019, 1, 12)}
Dim e2 As New employee With {.email = "bbb@bbb.bbb", .name = "nameEmp2", .DischargeDate = New Date(2018, 8, 24)}
Dim e3 As New employee With {.email = "ccc@ccc.ccc", .name = "nameEmp3", .DischargeDate = New Date(2017, 5, 12)}
e = New List(Of employee) From {{e1}, {e2}, {e3}}
Comps.Add(New company With {.name = "nameCom1", .emp = e})
Dim e4 As New employee With {.email = "ddd@ddd.ddd", .name = "nameEmp4", .DischargeDate = New Date(2014, 3, 22)}
Dim e5 As New employee With {.email = "eee@eee.eee", .name = "nameEmp5", .DischargeDate = New Date(2018, 4, 4)}
Dim e6 As New employee With {.email = "fff@fff.fff", .name = "nameEmp6", .DischargeDate = New Date(2017, 3, 26)}
e = New List(Of employee) From {{e4}, {e5}, {e6}}
Comps.Add(New company With {.name = "nameCom2", .emp = e})
Dim e7 As New employee With {.email = "ggg@ggg.ggg", .name = "nameEmp7", .DischargeDate = New Date(2019, 1, 8)}
Dim e8 As New employee With {.email = "hhh@hhh.hhh", .name = "nameEmp8", .DischargeDate = New Date(2018, 6, 30)}
Dim e9 As New employee With {.email = "iii@iii.iii", .name = "nameEmp9", .DischargeDate = New Date(2017, 2, 26)}
e = New List(Of employee) From {{e7}, {e8}, {e9}}
Comps.Add(New company With {.name = "nameCom3", .emp = e})
Я будуценим любое предложение или комментарий