Link to home
Start Free TrialLog in
Avatar of aspnet-scotland
aspnet-scotlandFlag 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.
SOLUTION
Avatar of p_davis
p_davis

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
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
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
Avatar of 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.
Thanks wdosanjos!
Avatar of p_davis
p_davis

thanks for the assist wdosanjos