Let’s suppose I have a model class like
class Player
{
String FirstName;
String LastName;
String Team;
int UniformNumber;
int Height;
}
Now I have a list of this class: List Players;
This list contains some instances, e.g.,
Players[0] = new Player(){
FirstName = "Kobe",
LastName = "Byrant",
Team = "Lakers",
UniformNumber = 24,
Height = 19}; //...
Is there a way I can get a sub List<Player>
type list, which contains same Height and same UniformNumber players?
Can someone show me a way to do it quickly(suppose there are 10 000 players in the list)? Does LINQ fast enought? Thanks.
[Edit] Before asking the question, I use below codes:
var subList = new List<Player>();
foreach (var player in players)
{
if (players.Where(p =>
(p.Height == player.Height) &&
(p.UniformNumber == player.UniformNumber )).Count() > 1)
{
subList.Add(item);
}
}
I can get the result, but it is really slow, so i want the suggestion, thanks.