0

Имеется список SaveList. Объект SavedList имеет значения int lvl, string Value и string Date. Мне нужно получить все объекты из списка, у которых lvl равен 1ому.

Т.е.: Из данного списка

SaveList[0]: lvl = 1, Value = "987", Date = "01.02.2005"
SaveList[1]: lvl = 2, Value = "123", Date = "06.07.2009"
SaveList[2]: lvl = 1, Value = "654", Date = "23.05.2012"

Должен получиться такой.

NewList[0]: lvl = 1, Value = "987", Date = "01.02.2005"
NewList[1]: lvl = 1, Value = "654", Date = "23.05.2012"

Извиняюсь за возможные ошибки в составлении вопроса.

1 ответ 1

3
class MyClass
{
    public int lvl;
    public string Value;
    public string Date;
}

class Program
{
    static void Main(string[] args)
    {
        List<MyClass> list = new List<MyClass>();

        //заполняем список...

        List<MyClass> filtered = list.Where(item => item.lvl == 1).ToList();
    }
}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.