Avatar of aspnet-scotland
aspnet-scotland
Flag for United Kingdom of Great Britain and Northern Ireland asked on

How do I order items within a C# List?

Hi,

I have the below code. I am filling a list with data objects. I have an "Order" property but I'm not too sure how I can alter my code to sort the data objects on this order property?

public List<PhoenixWCF.Brand> BrandsByCategoryId(int intBrandCategoryId)
        {
            List<PhoenixWCF.Brand> brands = new List<PhoenixWCF.Brand>();

            foreach (var brand in Brands)
            {
                if(brand.BrandCategoryId == intBrandCategoryId)
                    brands.Add(brand);
            }

            return brands;
        }

Open in new window


Thanks.
C#ASP.NET.NET Programming

Avatar of undefined
Last Comment
p_davis

8/22/2022 - Mon
SOLUTION
p_davis

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
MFlaig

brands.sort();

should sort it alphabetical but never heard of your type PhoenixWCF.Brand , maybe you can specify this a little further?
ASKER CERTIFIED SOLUTION
wdosanjos

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
aspnet-scotland

ASKER
I get the error "cannot implicitly convert type 'System.Linq.IOrderedEnumerable<PhoenixWCF.Brand>' to 'System.Collections.Generic.List<PhoenixWCF.Brand>'. An explicit conversion exists (are you missing a cast?)"?

Thanks.
aspnet-scotland

ASKER
Thanks wdosanjos!
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
p_davis

thanks for the assist wdosanjos