I have a list of objects and I want to check if there is objects with the same property values:
Level is an object, that means levels of a house and has a property called elevation.
listOflevels is a list of my object Level
I would like to know if in my list(listOflevels) there is two or more levels with the same elevation.
Ex.: If I have one level with level.elevation = 3 and another one with level.elevation = 3, then the method should return true
I tried this way, but I wonder if there is a better way
foreach (Level level in listOflevels)
{
double levelElevation = level.Elevation;
foreach (Level level2 in listOflevels)
{
if ((level2.Name != level.Name && level2.Elevation == levelElevation)
{
return true;
}
}
}
Can LINQ be used to improve this?
Many Thanks