I have a C# list named AxiomSubset
with 6 columns in which there are several rows of data and I would like to check if all the values of a particular column in the list are equal if they are equal then it should return true and go to the next column and check their equality and so on.
For Example, I have the following rows of data in the list
CC Mon str stg rate units
HP 15-Mar 4.0800 4
HP 15-Feb 4.0800 4
HP 15-Jan 4.0800 4
LN 15-Mar 3.25 Put 0.0500 50
LN 15-Feb 3.25 Put 0.0500 50
LN 15-Jan 3.25 Put 0.0500 50
LN 15-Mar 3.50 Put 0.1000 50
LN 15-Feb 3.50 Put 0.1000 50
LN 15-Jan 3.50 Put 0.1000 50
In the above data when checking the equality for column CC
it should return false as they are all not equal
I tried doing it as follows which compares one row with the earlier row which doesn't give expected results obviously
for (int i = 0; i < AxiomSubSet.Count; i++)
{
if (AxiomSubSet[i].CC.ToString() == AxiomSubSet[i + 1].CC.ToString())
{
result = true;
if (AxiomSubSet[i].term.ToString() == AxiomSubSet[i + 1].ToString())
{
//So On
}
}
}
Above code compares two values at a time and will return true if they are equal without considering other values which is something unwanted.
Is there a better way to do it?