列表按子句获取值

时间:2016-05-30 19:50:56

标签: c# list

如何添加 where 以获取并非所有值?

        var response = proxy.GetInformation(
            new TravelAgencyService.Messages.TravelAgencyRequest()
            {
                Accommodation = comboBox1.SelectedItem.ToString()
            });
        List<string> kindOfAccommodation = response.Offers
        .Select(o => o.RodzajZakwaterowania )
        .Distinct()
        //.Where()??
        .OrderBy(c => c)
        .ToList();

用户必须从comboBox中选择国家/地区,之后我想在这个国家/地区只选择一种住宿并在下一个comboBox中获取

1 个答案:

答案 0 :(得分:1)

试试这个:

 var response = proxy.GetInformation(
        new TravelAgencyService.Messages.TravelAgencyRequest()
        {
            Accommodation = comboBox1.SelectedItem.ToString()
        });
    List<string> kindOfAccommodation = response.Offers
    .Where(offer => offer.AttributeOfOffer == valueToFilter)
    .Select(o => o.RodzajZakwaterowania )        
    .Distinct()       
    .OrderBy(c => c)
        .ToList();