Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8168161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:25:41+00:00 2026-06-06T20:25:41+00:00

Sometimes I can’t understand the simplest things, i’m sure it’s in my face, i

  • 0

Sometimes I can’t understand the simplest things, i’m sure it’s in my face, i just fail to see it.
Im trying to create a delegate for a method in this simple class:

public static class BalloonTip
{
    public static BalloonType BalType
    { 
        get; 
        set; 
    }

    public static void ShowBalloon(string message, BalloonType bType)
    {
        // notify user
    }
}

Now, this Action<> is supposed to create the delegate without actually declaring one with the keyword “delegate”, did I understand correctly? Then:

private void NotifyUser(string message, BalloonTip.BalloonType ballType)
    {
        Action<string, BalloonTip.BalloonType> act; 
        act((message, ballType) => BalloonTip.ShowBalloon(message,  ballType));
    }

This fails to compile. Why?

(By the way, the reason why I need this delegate instead of directly calling ShowBalloon(), is that the calls must be made from another thread than the UI one, so I figured I need the Action<>)

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T20:25:44+00:00Added an answer on June 6, 2026 at 8:25 pm

    You need to first assign your anonymous method to the Action variable, then invoke it with the arguments passed in to the method:

    private void NotifyUser(string message, BalloonTip.BalloonType ballType)
    {
        Action<string, BalloonTip.BalloonType> act = 
            (m, b) => BalloonTip.ShowBalloon(m, b);
    
        act(message, ballType);
    }
    

    In this case, since the arguments expected by your Action variable are identical to those of the encapsulated method, you may also reference the method directly:

    private void NotifyUser(string message, BalloonTip.BalloonType ballType)
    {
        Action<string, BalloonTip.BalloonType> act = BalloonTip.ShowBalloon;
    
        act(message, ballType);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sometimes you can see: do_this do available_method1 arg1 available_method2 arg1 end When I use
I know what it does. If I dont use sometimes I can see the
Sometimes we can see that after clicking some share button, a list of sharable
When using SendGatewayMessage it can sometimes fail if the Maximum number of events to
Sometimes jpgraph can not create graph, in a case of NULL values. How can
I noticed today that auto-boxing can sometimes cause ambiguity in method overload resolution. The
I am learning java for 3 months and sometimes i can not understand the
I have some problem with MySQL Workbench in that I sometimes can't set foreign
Our mysql processes can sometimes get backlogged and processes begin queuing up. I'd like
Actually my problem is sometimes i can get the location and sometimes i can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.