none
Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement

    Question

  • Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement

    error at ( of 

    (_sender, _e) =>
    public object hello(object instance, string event_name)
            {
                EventHandler handler = null;
                (_sender, _e) =>
                {
                    Console.WriteLine("");
    	    }
    	}


    ---v-----!

    Friday, October 25, 2013 3:17 AM

Answers

  • I am not able to fully understand your code, but, anyways try the below code,

    public object Wait(object instance, string event_name)
    { // ←[A]
        EventHandler handler = null;
        handler = (_sender, _e) =>
            {
                //Console.WriteLine("");
                // ←[C]
                instance.GetType().GetEvent(event_name).GetRemoveMethod()
                    .Invoke(instance, new[] { handler }); // ←[K]
                _Etor.MoveNext(); // ←[F]
            };
        instance.GetType().GetEvent(event_name).GetAddMethod()
            .Invoke(instance, new[] { handler }); // ←[D]
        return null; // ←[L]
    }

    I hope this helps.


    Please mark this post as answer if it solved your problem. Happy Programming!

    • Marked as answer by oooooxxxxx Friday, October 25, 2013 9:06 AM
    Friday, October 25, 2013 7:04 AM

All replies

  • have a look at lambda expressions

    Mark Answered, if it solves your question and Vote if you found it helpful.
    Rohit Arora

    Friday, October 25, 2013 4:22 AM
  • Hi,

    you just make a misunderstanding about Lambda, 

    http://msdn.microsoft.com/en-us/library/vstudio/bb397687.aspx

    so, can you make sense what your error is? You can't just use (_sender, _e), you need a left expression.


    Every answer may help a lot, thanks guys
    Frank

    Friday, October 25, 2013 4:25 AM
  • Ok. May be you have copy pasted the code. Here is the correct code.

    public object hello(object instance, string event_name)
    {
        EventHandler handler = (_sender, _e) =>
        {
             Console.WriteLine("");
        }
    }

    I hope this helps.


    Please mark this post as answer if it solved your problem. Happy Programming!

    Friday, October 25, 2013 5:10 AM
  • i use the example here , failed to compile

    http://simonpg.web.fc2.com/Pages/labo/idea_p/20091001_UseYieldForWait/index.html

    public object Wait(object instance, string event_name)
            { // ←[A]
                EventHandler handler = (_sender, _e) =>
                {
                    //Console.WriteLine("");
                    // ←[C]
                    instance.GetType().GetEvent(event_name).GetRemoveMethod()
                        .Invoke(instance, new[] { handler }); // ←[K]
                    _Etor.MoveNext(); // ←[F]
                };
                instance.GetType().GetEvent(event_name).GetAddMethod()
                    .Invoke(instance, new[] { handler }); // ←[D]
                return null; // ←[L]
            }


    ---v-----!

    Friday, October 25, 2013 6:46 AM
  • I am not able to fully understand your code, but, anyways try the below code,

    public object Wait(object instance, string event_name)
    { // ←[A]
        EventHandler handler = null;
        handler = (_sender, _e) =>
            {
                //Console.WriteLine("");
                // ←[C]
                instance.GetType().GetEvent(event_name).GetRemoveMethod()
                    .Invoke(instance, new[] { handler }); // ←[K]
                _Etor.MoveNext(); // ←[F]
            };
        instance.GetType().GetEvent(event_name).GetAddMethod()
            .Invoke(instance, new[] { handler }); // ←[D]
        return null; // ←[L]
    }

    I hope this helps.


    Please mark this post as answer if it solved your problem. Happy Programming!

    • Marked as answer by oooooxxxxx Friday, October 25, 2013 9:06 AM
    Friday, October 25, 2013 7:04 AM