Thread: Action object

  1. #1
    Registered User
    Join Date
    Jan 2007

    Action object

    consider this code:

            private void DoIf(bool b, Action f)
                if (b)
    int x = 0;
    bool no = false;
    DoIf(no, () => x = 10);
    Does the compiler emit code to create a new action when the function is called or only when f() is actually called?

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Oregon, USA
    Are you asking about the CLR or the compiler? The compiler is going to do its thing independently of any runtime constraints such as branching.
    If you understand what you're doing, you're not learning anything.

  3. #3
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    The Action object is syntactic sugar for a delegate taking one argument and returning void. The CLR will defined the object as a sealed class deriving from System.MulticastDelegate and define three public member functions; Invoke, BeginIvoke and EndInvoke. The CIL will call these member functions whenever you use the object.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very strange file action
    By JayCee++ in forum C++ Programming
    Replies: 5
    Last Post: 07-01-2012, 06:01 AM
  2. When does an action exist?
    By Yarin in forum General Discussions
    Replies: 18
    Last Post: 10-18-2009, 01:50 PM
  3. Action Game - AI Contest
    By Queatrix in forum Contests Board
    Replies: 4
    Last Post: 01-18-2007, 06:55 PM
  4. action whilst downloading
    By eth0 in forum C Programming
    Replies: 5
    Last Post: 05-05-2005, 03:58 AM
  5. how do I perform an action over and over...
    By Rune Hunter in forum C# Programming
    Replies: 16
    Last Post: 02-25-2005, 11:03 AM