Question: Lets say I have two lists of colors and I need to compare them. I have a function of comparing colors but I'm a little bit confused of types which function gets. How to cast them?

```
public bool AreColorsSimilar(Color c1, Color c2, int tolerance)
{
    return Math.Abs(c1.R - c2.R) < tolerance &&
           Math.Abs(c1.G - c2.G) < tolerance &&
           Math.Abs(c1.B - c2.B) < tolerance;
}

```

Here is my first list: 

```
public static List<Color> PaletteOfSeasons()
{
    List<Color> springColors = new List<Color>();

    springColors.Add(ColorTranslator.FromHtml("#80a44c"));
    springColors.Add(ColorTranslator.FromHtml("#b4cc3a"));

    return springColors;
}

```

And in another list I'm pulling pixels from image: 

```
public static IEnumerable<Color> GetPixels(Bitmap bitmap)
{
    for (int x = 0; x < bitmap.Width; x++)
    {
        for (int y = 0; y < bitmap.Height; y++)
        {
            Color pixel = bitmap.GetPixel(x, y);
            yield return pixel;
        }
    }
}

```

And question is, how can I compare this colors ?

Answer: 
If I understand you right:

```
var springColors = null;
springColors = PaletteOfSeasons(springColors);

var similarColors = GetPixels(bitmap).Intersect(springColors, new ColorComparer(tolerance));

```

And you need this class:

```
public class ColorComparer : IEqualityComparer<Color> 
{
    private _tolerance;

    public ColorComparer(int tolerance)
    {
        _tolerance = tolerance;
    }

    public bool Equals(Color x, Color y)
    {
        return AreColorsSimilar(x, y, _tolerance);
    }

    public int GetHashCode(Foo x)
    {
        return 0;
    }

    private bool AreColorsSimilar(Color c1, Color c2, int tolerance)
    {
        return Math.Abs(c1.R - c2.R) < tolerance &&
           Math.Abs(c1.G - c2.G) < tolerance &&
           Math.Abs(c1.B - c2.B) < tolerance;
    }
}

```

P.S. Your method PaletteOfSeasons is a little confusing. Passing list to method foolishly.

P.P.S. Use Bitmap.LockBits() to increase code performance.

P.P.P.S. Such implementation of GetHashCode isn't good. But in our situation it is OK.
Simply compare all pixels of the bitmap with all the colors in the palettes:

```
foreach(var pixel in GetPixels(myBitmap))
{
    foreach(var candidate in paletteOfSeasons)
    {
        if(AreColorsSimilar(pixel, candidate, 42)
        {
            // Hooray, found some similar colors.
        }
    }
}

```