|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
help on generic spacethe 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; "GS" <gsmsnews.microsoft.co***@msnews.Nomail.com> wrote in message The error message itself tells you what the argument to "Find" should 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 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); Alberto Poblacion wrote:
Show quoteHide quote > "GS" <gsmsnews.microsoft.co***@msnews.Nomail.com> wrote in message Or you could just use the right method. IndexOf is what most people want > 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); 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. 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 'System.Collections.Generic.List<System.Drawing.Color>.Find(System.Predicatenews:%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 > >> 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. > > "Ben Voigt [C++ MVP]" <bvoigt@newsgroup.nospam> wrote in message What is this "Set" of which you speak? The only thing I found in MSDN was a news:%23MxEHmS8JHA.1376@TK2MSFTNGP02.phx.gbl... > But using a better container, like a Set, would be even better. C++ STL thing. Jeff Johnson wrote:
> "Ben Voigt [C++ MVP]" <bvoigt@newsgroup.nospam> wrote in message e.g. http://www.codeplex.com/PowerCollections> 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. 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 On Thu, 02 Jul 2009 07:05:03 -0700, Ben Voigt [C++ MVP]
<bvoigt@newsgroup.nospam> wrote: > Jeff Johnson wrote: No, the docs are still in beta. HashSet<T> has been in there since 3.5.>> "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 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
Other interesting topics
What am I doing wrong with GCHandle here...
Help with Streams OT: Binary Search - Should They Know It? Appliation.Exit not killing my Threads Re-opening file streams Need NCover-help as I'm trying to gauge the code coverage of my .NET modules Adding Document properties to a data file StatusStrip control question Mismatch between foreign key and primary key is not detected Moving file into folder... file doesn't inherit folder permissions? |
|||||||||||||||||||||||