So I have mentioned before that LADotNet.org runs a Masters Series on Saturdays and this Saturday is no different. This week it is being presented by Ken Getz. Ken is a great presenter and we are glad to have him back in California (Sorry Florida). Anyway, as he was going through delegates and events and he covered something I was not aware of.
Anonymous Delegates. Whenever I used delegates in the past, I aways had a method that could be passed that would handle the call. You can also pass a proceedure or "Block of Code" instead of passing a pointer to a method like below. (Both C# and VB)
184 static void AnonymousDelegate()
185 {
186 FileSearch4 fs =
187 new FileSearch4("C:\\", FILESPEC, false);
188 fs.Handler =
189 delegate(FileInfo file)
190 {
191 Console.WriteLine("{0} ({1})",
192 file.FullName, file.Attributes);
193 };
194 fs.Execute();
195 }
I am not sure of a real use for this but it was interesting to see someting new.
Doc