[Mono-bugs] [Bug 394347] Anonymous delegates do strange things.

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Sep 18 16:43:44 EDT 2008


https://bugzilla.novell.com/show_bug.cgi?id=394347

User dustin.breese at gmail.com added comment
https://bugzilla.novell.com/show_bug.cgi?id=394347#c5


Dustin Breese <dustin.breese at gmail.com> changed:

           What    |Removed                                         |Added
----------------------------------------------------------------------------
                 CC|                                                |dustin.breese at gmail.com




--- Comment #5 from Dustin Breese <dustin.breese at gmail.com>  2008-09-18 14:43:44 MDT ---
The workaround seems to be that you can cast your anonymous delegate as
follows:

class MainClass
    {
        delegate string SomeDelegate();

        public static void Main(string[] args)
        {
            Dictionary<string, SomeDelegate> dictionary = new
Dictionary<string, SomeDelegate> ();
                        dictionary ["TEST"] = (SomeDelegate)delegate { return
"In the delegate!"; };

            // See if the delegate is invoked
            SomeDelegate someDelegate;
            bool result = dictionary.TryGetValue ("TEST", out someDelegate);
            Console.WriteLine("Was it found? " + result);
            Console.WriteLine("Result = " + someDelegate());
        }

This will also fix bug https://bugzilla.novell.com/show_bug.cgi?id=369538
causing issues in MonoDevelop.


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list