Member 13677196 Ответов: 3

Здесь я создал список, в котором есть имена профилей, и я хочу отсортировать их по алфавиту в порядке убывания.


foreach (var eachProfileUri in AllAssociatedProfileUrisList)
{
    var eachProfileData = CallRestApi("https://" + con.oneViewIP + eachProfileUri, "GET", con.sessionID, con.xApiVersionString);
    var data = eachProfileData["enclosureUri"];
    var enclosuredetails = CallRestApi("https://" + con.oneViewIP + data, "GET", con.sessionID, con.xApiVersionString);
    if (enclosuredetails["enclosureType"].ToString() != "C7000")
    {
        associatedprofileSetList.Add(eachProfileData["name"].ToString());

    }
    else if (enclosuredetails["enclosureType"].ToString() != "SY12000")
    {
             associatedprofileSetList.Add(eachProfileData["name"].ToString());

    }
}
if (associatedprofileSetList.Count() > 0)
{
    //associatedprofileSetList.OrderByDescending(x => x.Product.Name).ToList();
    var assoProfileset = String.Join(",", associatedprofileSetList);
    NetworkDict.Add(property, assoProfileset);
}


[edit]добавлен блок кода - OriginalGriff[/edit]

Что я уже пробовал:

Я попытался создать список, а затем попытаться отсортировать список по алфавиту в порядке убывания. пожалуйста, помогите мне . Я не в состоянии сделать это.

3 Ответов

Рейтинг:
4

OriginalGriff

Попробуй:

List<string> sorted = associatedprofileSetList.OrderbyDescending(a => a).ToList();


Рейтинг:
21

#realJSOP

Попробуйте сделать это таким образом:

if (associatedprofileSetList.Count() > 0)
{
    //associatedprofileSetList.OrderByDescending(x => x.Product.Name).ToList();
    var assoProfileset = String.Join(",", associatedprofileSetList.OrderByDescending(x => x.Product.Name).ToList());
    NetworkDict.Add(property, assoProfileset);
}


Рейтинг:
19

F-ES Sitecore

OrderBy возвращает копию списка в нужном вам порядке, он не изменяет список, в котором вы используете OrderBy. Так что вам нужно сделать;

associatedprofileSetList = associatedprofileSetList.OrderByDescending(x => x.Product.Name).ToList();


Примеры[^]