0

so I am working on my final year project and I had an algorithm to find the difference between 2 routes. however, my algorithm is too long and it's only if else statements all over the place 200 lines of if else statement. I am sure there is an easier what I did not think of I will show you and example.

 for (int x = 0; x < networkElements.Count - 1; x++)
        {
            for (int i = x + 1; i < networkElements.Count; i++)
            {
                if (networkElements.ElementAt(x).Description.Equals(networkElements.ElementAt(i).Description))
                {
                    if (networkElements.ElementAt(x).Port1.Equals(networkElements.ElementAt(i).Port1))
                    {
                        if (networkElements.ElementAt(x).Port2.Equals(networkElements.ElementAt(i).Port2))
                        {


                           Console.WriteLine("Both Routes are identical\n");
                            comparisonReults.Add(networkElements.ElementAt(x));
                        }
                        else
                        {
                            Console.WriteLine("Port 2 is different\n" +
                                "Port 2 for route 1 = " + networkElements.ElementAt(x).Port2 + " Port 2 for route 2 = " + networkElements.ElementAt(i).Port2 + "\n");
                           }
                    }
                    else
                    {
                        Console.WriteLine("Port 1 is different\n" +
                                "Port 1 for route 1 = " + networkElements.ElementAt(x).Port1 + " Port 1 for route 2 = " + networkElements.ElementAt(i).Port1 + "\n");

                        if (!networkElements.ElementAt(x).Port2.Equals(networkElements.ElementAt(i).Port2))
                        {
                            Console.WriteLine(" Also port 2 is different\n" +
                                "Port 2 for route 1 = " + networkElements.ElementAt(x).Port2 + " Port 2 for route 2 = " + networkElements.ElementAt(i).Port2 + "\n");
                            else
                        {
                           Console.WriteLine("\n port 2 the same port 1 is different");
                        }
                    }
                }
                else
                {
                    Console.WriteLine("\n completey different routes not eligable for comparison");

                    }

However, I was revising the method and something came to my mind can't I just use this:

if (!route1.Equal(route2)){
    //fill in here stackoverflow
    //is there a function for example route1.getDifference(route2)
    //built in function to compare properties
}
else{
     //they are identical
    }
jack2009
  • 1
  • 1

0 Answers0