c# list

Hello,

i have a question about List.

This is my class:
 public class XMLProfile
    {

            public Single Calculation1 { get; set; }
            public Single Calculation2 { get; set; }
            public Single Calculation3 { get; set; }
            public int Id { get; set; }

    }

Open in new window


I use this method to populate list:
 public static List<XMLProfile> ParseXmlProfile()
        {

            doc = XDocument.Load(Document);

            List<XMLProfile> result = (from c in doc.Descendants("CalcTag")
                                 orderby c.Attribute("id").Value 
                                 select new XMLProfile()
                                 {
                                     Id = (int)(c.Attribute("id")),
                                     Calculation1 = (float)c.Attribute("Calculation1"),
                                     Calculation2 = (float)c.Attribute("Calculation2"),
                                     Calculation3 = (float)c.Attribute("Calculation3")
                                 }).ToList();

           
            return result;
        }

Open in new window


Now my question is what would a function look like that will go trought elements on list from smallest ID to largest ID.
When reaching last ID read order would be reversed from last id (largest) to first ID (smallest)?

Thank you!
TagyourareitAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chaauCommented:
It will be "descending":

List<XMLProfile> result = (from c in doc.Descendants("CalcTag")
                                 orderby c.Attribute("id").Value descending 
                                 select new XMLProfile()
                                 {
                                     Id = (int)(c.Attribute("id")),
                                     Calculation1 = (float)c.Attribute("Calculation1"),
                                     Calculation2 = (float)c.Attribute("Calculation2"),
                                     Calculation3 = (float)c.Attribute("Calculation3")
                                 }).ToList();

Open in new window

TagyourareitAuthor Commented:
Hello,

yes that would be loading XML to list in descending order.

What i am wondering is ... i have my XML in an object already ... how would i reverse read it whit in that list without parsing XML file again.
TagyourareitAuthor Commented:
What i basically need is something like this:

Reading XML file:

1
2
3
4
5

I have reached max index
so now i i will reverse read it

5
4
3
2
1
I have reached last index again
1
2
3
4
5


This should be a continious loop ...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TagyourareitAuthor Commented:
Self solved the problem.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.