Compare values from list

Hello Experts,

i have a following problem:

so far in my demonstration example (see code below)  i have a class for storing values i get from parsing an Xml file some other functions.

    class Program
    {

        public static XDocument doc = null;
        public static string Dokument = "";

        static void Main(string[] args)
        {
            DisplayXmlParsedObjects();
            Console.ReadLine();
        }


        public static List<XmlParseObject> XmlParse()
        {

            doc = XDocument.Load(Dokument);

            var result = from c in doc.Descendants("HotSpot")
                         select new XmlParseObject()
                         {
                             Id = (int)(c.Attribute("id")),
                             x = (float)c.Attribute("x"),
                             y = (float)c.Attribute("y"),
                             z = (float)c.Attribute("z")
                         };

            List<XmlParseObject> ListResults = new List<XmlParseObject>();

            foreach (var item in result)
            {
                ListResults.Add(new XmlParseObject() { x = item.x, y = item.y, z = item.z, Id = item.Id });
            }

            ListResults.Add(new XmlParseObject() { x = 666f, y = 666f, z = 666f, Id = 0 });

            return ListResults;
        }

        public static void DisplayXmlParsedObjects()
        {
            List<XmlParseObject> results = XmlParse();

            if (results != null)
            {
                // Enumerate through the XmlParseObject objects and displey the info 
                foreach (XmlParseObject obj in results)
                {
                    Console.WriteLine("{0,-4}{1,-10}{2,-11}{3,-8}",
                        obj.Id, obj.x, obj.y, obj.z);
                }
            }
        }

    }


    public class XmlParseObject
    {
        public float x { get; set; }
        public float y { get; set; }
        public float z { get; set; }
        public int Id { get; set; }
    }

Open in new window


What i am missing is a function that will be able to compare values. Lets say i have 3 entries in my List (see XML structure)

<?xml version="1.0" encoding="utf-8"?>
<start>
	 <HotSpot id="1" x="67216.14" y="-75172.24" z="-2984.153"/>
	 <HotSpot id="2" x="66326.78" y="-74404.68" z="-3172.191"/>
	 <HotSpot id="3" x="66220.13" y="-73542.97" z="-3286.478"/>
</start>

Open in new window


What funtion should do is:

Take List entry with ID=0 and compare it with ID=1 { some code }
Take List entry with ID=1 and compare it to ID=2 {come code}
Take List with ID=2 and comare to ID=2 and so on untill last node stored in list

and then repeate the loop (console y/n if u want to repeate.)

Thank you for reading and let me know if my question is unclear.
TagyourareitAsked:
Who is Participating?
 
Kyle AbrahamsSenior .Net DeveloperCommented:
Make results a member of the class.
    List<XmlParseObject> ListResults = new List<XmlParseObject>();

then:
     public static void CompareList()
    {
     do 
    {
       for (int i = 0; i < ListResults.Count - 2; i++)
       {
               XmlParseObject obj1 = results[i];
               XmlParseObject obj2 = results[i+1];
              // do your compare.
               
       }
     } while(1);            //change while(1) to get the choice from the console.
    }

Open in new window

0
 
käµfm³d 👽Commented:
Where is the "list"? Is it the x, y, and z values?
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
Completely off topic.
@Kaufmed
SNAG-0015.bmpHave you done anything or is my browser behaving strangely?
0
 
TagyourareitAuthor Commented:
Awesome!

thank you!
0
 
TagyourareitAuthor Commented:
@Kaufmed What do you mean?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.