Home All Groups Group Topic Archive Search About
Author
19 Jun 2009 5:40 AM
GS
I only dabble in C# once in a long while and am I lost. I got problem with
the following code
How should I reconcile
    Color c2 = colors.Find(c1)
so I don't get
Error 1 The best overloaded method match for
'System.Collections.Generic.List<System.Drawing.Color>.Find(System.Predicate
<System.Drawing.Color>)' has some invalid arguments

===================
List<Color> colors = new List<Color>(256);
            Color c1, c2;
            int i, j, nc = 0, ih = bmp.Height, iw = bmp.Width;
            const int IMax = 32;
            for (i = 0; i < Math.Min(iw, IMax); i++)
            {
                //find number of colors
                for (j = 0; j < Math.Min(ih,IMax); j++)
                {
                    c1 = bmp.GetPixel(i, j);
                    if (i == 0 & j == 0)
                    {
                        colors.Add(c1);
                    }
                    else
                    {
                        c2 = colors.Find(c1);
                        if (c2 == null)
                        {
                            colors.Add(c1);
                            if (nc > 256)
                            {
                                MessageBox.Show("Warning - input image has
more than 256 colors and maybe rejected by Visual Studio as application
icon");
                                return false;
                            }
                            else nc++;
                        }
                    }
                }
            }
            return true;

Author
19 Jun 2009 7:05 AM
Alberto Poblacion
"GS" <gsmsnews.microsoft.co***@msnews.Nomail.com> wrote in message
news:uhIGmBK8JHA.4820@TK2MSFTNGP04.phx.gbl...
>
> I only dabble in C# once in a long while and am I lost. I got problem with
> the following code
> How should I reconcile
>    Color c2 = colors.Find(c1)
> so I don't get
> Error 1 The best overloaded method match for
> 'System.Collections.Generic.List<System.Drawing.Color>.Find(System.Predicate
> <System.Drawing.Color>)' has some invalid arguments

    The error message itself tells you what the argument to "Find" should
be: it is expecting a Predicate<Color>, which means "a delegate to a
function that takes a Color and returns a Boolean". You can provide such a
delegate by means of a Lambda:

Color c2 = colors.Find(c=>c==c1);
Are all your drivers up to date? click for free checkup

Author
19 Jun 2009 10:01 PM
Ben Voigt [C++ MVP]
Alberto Poblacion wrote:
Show quoteHide quote
> "GS" <gsmsnews.microsoft.co***@msnews.Nomail.com> wrote in message
> news:uhIGmBK8JHA.4820@TK2MSFTNGP04.phx.gbl...
>>
>> I only dabble in C# once in a long while and am I lost. I got
>> problem with the following code
>> How should I reconcile
>>    Color c2 = colors.Find(c1)
>> so I don't get
>> Error 1 The best overloaded method match for
>> 'System.Collections.Generic.List<System.Drawing.Color>.Find(System.Predicate
>> <System.Drawing.Color>)' has some invalid arguments
>
>    The error message itself tells you what the argument to "Find"
> should be: it is expecting a Predicate<Color>, which means "a
> delegate to a function that takes a Color and returns a Boolean". You
> can provide such a delegate by means of a Lambda:
>
> Color c2 = colors.Find(c=>c==c1);

Or you could just use the right method.  IndexOf is what most people want
when Find isn't working, for this particular case Contains would solve the
problem better.  But using a better container, like a Set, would be even
better.
Author
19 Jun 2009 11:29 PM
GS
thx. I took up your suggestion and replace c2 with into int c1Idx and then
compare to less than 1. worked like a charm..

thank you again.


I must be too tired not able to think clearly.

I am somewhat better after some extra sleep although still not quite enough
quality sleep

"Ben Voigt [C++ MVP]" <bvoigt@newsgroup.nospam> wrote in message
news:%23MxEHmS8JHA.1376@TK2MSFTNGP02.phx.gbl...
> Alberto Poblacion wrote:
> > "GS" <gsmsnews.microsoft.co***@msnews.Nomail.com> wrote in message
> > news:uhIGmBK8JHA.4820@TK2MSFTNGP04.phx.gbl...
> >>
> >> I only dabble in C# once in a long while and am I lost. I got
> >> problem with the following code
> >> How should I reconcile
> >>    Color c2 = colors.Find(c1)
> >> so I don't get
> >> Error 1 The best overloaded method match for
> >>
'System.Collections.Generic.List<System.Drawing.Color>.Find(System.Predicate
Show quoteHide quote
> >> <System.Drawing.Color>)' has some invalid arguments
> >
> >    The error message itself tells you what the argument to "Find"
> > should be: it is expecting a Predicate<Color>, which means "a
> > delegate to a function that takes a Color and returns a Boolean". You
> > can provide such a delegate by means of a Lambda:
> >
> > Color c2 = colors.Find(c=>c==c1);
>
> Or you could just use the right method.  IndexOf is what most people want
> when Find isn't working, for this particular case Contains would solve the
> problem better.  But using a better container, like a Set, would be even
> better.
>
>
Author
26 Jun 2009 5:44 PM
Jeff Johnson
"Ben Voigt [C++ MVP]" <bvoigt@newsgroup.nospam> wrote in message
news:%23MxEHmS8JHA.1376@TK2MSFTNGP02.phx.gbl...

> But using a better container, like a Set, would be even better.

What is this "Set" of which you speak? The only thing I found in MSDN was a
C++ STL thing.
Author
2 Jul 2009 2:05 PM
Ben Voigt [C++ MVP]
Jeff Johnson wrote:
> "Ben Voigt [C++ MVP]" <bvoigt@newsgroup.nospam> wrote in message
> news:%23MxEHmS8JHA.1376@TK2MSFTNGP02.phx.gbl...
>
>> But using a better container, like a Set, would be even better.
>
> What is this "Set" of which you speak? The only thing I found in MSDN
> was a C++ STL thing.

e.g. http://www.codeplex.com/PowerCollections

I thought .NET had added a set class.... apparently it's still in beta:
http://msdn.microsoft.com/en-us/library/bb397727(VS.100).aspx
Author
2 Jul 2009 5:07 PM
Peter Duniho
On Thu, 02 Jul 2009 07:05:03 -0700, Ben Voigt [C++ MVP] 
<bvoigt@newsgroup.nospam> wrote:

> Jeff Johnson wrote:
>> "Ben Voigt [C++ MVP]" <bvoigt@newsgroup.nospam> wrote in message
>> news:%23MxEHmS8JHA.1376@TK2MSFTNGP02.phx.gbl...
>>
>>> But using a better container, like a Set, would be even better.
>>
>> What is this "Set" of which you speak? The only thing I found in MSDN
>> was a C++ STL thing.
>
> e.g. http://www.codeplex.com/PowerCollections
>
> I thought .NET had added a set class.... apparently it's still in beta:
> http://msdn.microsoft.com/en-us/library/bb397727(VS.100).aspx

No, the docs are still in beta.  HashSet<T> has been in there since 3.5.

I actually posted a detailed reply to the OP when his question first 
appeared, including describing HashSet<T> as a possible solution (with 
code example).  But, given recent problems with my posts being blocked by 
Microsoft's servers, it's possible no one else saw the post:

http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/958a199d179b08d9

Pete

Bookmark and Share