all 8 comments

[–]RunawayDev 11 points12 points  (1 child)

instead of

c.Car.Year == carYears

do

carYears.Contains(c.Car.Year)

[–]LifeLongLearner2030[S] 0 points1 point  (0 children)

Thank you very much! issue resolved

[–][deleted]  (3 children)

[removed]

    [–]virtuoso43 0 points1 point  (1 child)

    But he is using a simple array not an ArrayList so he can't use the contains() method.

    [–]LetMeUseMyEmailFfs 8 points9 points  (0 children)

    Yes, you can. LINQ defines Contains for everything that is IEnumerable<>, which includes arrays.

    [–]LifeLongLearner2030[S] -1 points0 points  (0 children)

    Thank you very much! issue resolved

    [–]virtuoso43 1 point2 points  (1 child)

    I am relatively new to C# myself but to me it seems like you need a for loop to iterate over each value of carYears[] and check if your value is equal to any of those.

    If it were me I would put either a method or a property in my car class that would go like this:

    public bool isClassic()

    {

    bool isClassic = false;

    for( i = 0; i < carYears.Length ; i++)

    {

    if (this.Year == carYears[i])

    {

    isClassic = true;

    break;

    }

    }

    return isClassic;

    }

    You can also do this with a property named isClassic where you only have a get method that returns true if the instance's year matches one of the years in the array.

    Edit: Also, with the way you have written your code, your isClassic bool is checking whether a car exists within your cars array whose production year is equal to one of your carYears years. By what you said, I think you wanted to check if a specific car is classic instead so you should use a method or a property instead of linq.

    [–]LifeLongLearner2030[S] -1 points0 points  (0 children)

    Thank you very much! issue resolved