What will be the best way to replace:
for(int i=0; i<10; i++)
{
if(!members[i].Equals(anotherMembers[i]))
{
return false;
}
}
with LINQ expression?
What will be the best way to replace:
for(int i=0; i<10; i++)
{
if(!members[i].Equals(anotherMembers[i]))
{
return false;
}
}
with LINQ expression?
I don't think LINQ would be more readable option, but in general you need to Zip
sequences first to be able to deal with pairs at the same index:
var allSame = members.Zip(anotherMemebers, (x,y)=> Tuple.Create(x,y))
.All(t => t.Item1.Equals(t.Item2)); // or other operation on pairs
As Habib pointed out if you just need to compare sequences SequenceEqual may be better choice.
As @juharr commented .Take(10)
may be needed to close match original loop, but LINQ versions are way more forgiving - you'd need to check item count to exactly match all "out of range" errors from original loop.