Linq help using "Contains"

Posted by Kettenbach on Stack Overflow See other posts from Stack Overflow or by Kettenbach
Published on 2010-03-18T17:41:21Z Indexed on 2010/03/18 17:51 UTC
Read the original article Hit count: 442

Filed under:
|
|
|

Good Morning All,

I'm trying to use "Contains" to see if an object is within the collection. When I break I can see that the object is indeed part of the collection however "Contains" seems to be returning false indicating the item is not in the collection. Any idea what I'm doing wrong?

if(HttpContext.Current.Session["AutoPayTypes"] != null)
{
    var autopays = HttpContext.Current.Session["AutoPayTypes"] as List<PaymentTypeInfo>;
    char? coverageProductLine = null;

    if(entityProps.ContainsKey("CoverageProductLine"))
    {
       coverageProductLine = (char?)entityProps["CoverageProductLine"];
    }

    var paymentTypeInfoRepository = new PaymentTypeInfoRepository();
    var payType = paymentTypeInfoRepository.GetPaymentTypeInfo(paymentAdd.PayType,
    coverageProductLine);

    if (autopays != null && payType != null)
        paymentAdd.DaysPaid = autopays.Contains(payType) ? null : paymentAdd.DaysPaid;
}

If the object is not in the collection the "DaysPaid" needs to be null. Any ideas?

Thanks, ~ck in San Diego

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about c#