Link to home
Start Free TrialLog in
Avatar of Tagyourareit
Tagyourareit

asked on

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.
Avatar of kaufmed
kaufmed
Flag of United States of America image

Where is the "list"? Is it the x, y, and z values?
ASKER CERTIFIED SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Completely off topic.
@Kaufmed
User generated imageHave you done anything or is my browser behaving strangely?
Avatar of Tagyourareit
Tagyourareit

ASKER

Awesome!

thank you!
@Kaufmed What do you mean?