With your setup, I am assuming you would perform a LINQ query every time you need to search for a particular team. A better approach would be to have a linear structure, such as a dictionary, which has name as a key.
Keeping close to what you got there, here is some code to play with:
Option Strict On
Public Class Form1
Class MyGroup
Public Teams As New List(Of MyTeam)
End Class
Class MyTeam
Public Players As New List(Of MyPlayer)
Public TeamName As String
End Class
Class MyPlayer
Public PlayerName As String
End Class
Dim m_Groups As New List(Of MyGroup)
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim p As New MyPlayer With {.PlayerName = "Player"}
Dim t As New MyTeam With {.TeamName = "Team", .Players = New List(Of MyPlayer)({p})}
m_Groups.Add(New MyGroup With {.Teams = New List(Of MyTeam)({t})})
Dim name As String = "Player" 'player name to be searched
Dim teamName = (From group In m_Groups _
From team In group.Teams _
From player In team.Players _
Where player.PlayerName.Equals(name) _
Select team.TeamName).FirstOrDefault()
End Sub
End Class
It was heavily influenced by @millimoose's answer, with two slight changes:
Dim team -> Dim teamName, you cannot have two team variables in the same scope.
- OP wants the team name, so
Select player became Select team.TeamName.