如何对列表进行排序

3
我在Sitefinity中有一个函数,它返回一个类别列表。
//return list of categories
    private IList<ICategory> GetCategoryDataSource() {

        var cntManager = new ContentManager(CaseStudyManager.DefaultContentProvider);
        IList allCategories = cntManager.GetCategories();
        List<ICategory> filteredList = new List<ICategory>();
        foreach (ICategory category in allCategories) {

            filteredList.Add(category);

        }
        return filteredList;
    }

我想知道的是如何对这个列表进行排序。
据我所知,Sitefinity中的分类只是一个字符串,没有与分类相关联的其他字段。因此,我没有其他可用于对分类进行排序的信息,除了给每个分类添加一个数字,例如:
1 - Legal
2 - Financial
3 - Property

当这些类别显示在网站上时,至少我可以剪裁我需要的部分。
但是,有人能帮忙分类吗?
谢谢 Al

这并不回答你的问题,但你可以删除你的foreach/add语句,并将其替换为:filteredList.AddRange(allCategories)。 - Dismissile
6
ICategory接口中没有其他属性吗?没有可以使用的Id或CategoryId吗?return filteredList.OrderBy(x => x.CategoryId).ToList() - Martin
2个回答


0
如果您按照您提及的方式对它们进行命名,并加上前缀,您可以这样做:
001 | xxxxxxx
002 | djskdjskd
003 | sdkdsajdaks
foreach (ICategory category in allCategories) 
{              
    filteredList.Add(category.SubString(4);          
} 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接