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 8058167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:16:05+00:00 2026-06-05T09:16:05+00:00

I want to encapsulate delegate methods, which will be invoked later on. This delegate

  • 0

I want to encapsulate delegate methods, which will be invoked later on. This delegate method, when invoked, will calculate some arguments at that instance of time and assign/return the value to a variable outside of the class.

For example, I have a class Tool

This tool should generate, let’s say Point, when the delegate method is called…

public delegate void Action();

class Tool
{
public Action Select;
public Action Cancel;
public Point position;
public Tool(ref Point outPoint) //Cannot use ref with lambda...
{
Select = () => outPoint = position;
}

public void Update(Point newPosition)
{
position = newPosition
}
public void UpdateKey(Keys k, bool IsPress)
{
//Invoke Select/Cancel when press some keys
}

}

What I am trying to accomplish here is a simple function that should receive my input and fill it with correct argument after Select is invoked. If this was a single method, then it is easily done using ref. However, I have to keep track of many arguments, so I have to turn it into a class. Another thing is, this invocation happens inside the class, so I cannot return the calculated value from within the class. Even though I could change the design so that the update method is updated from outside of the class, what I desire is to have the class manages its own update routines. I know that there should be a better way, so if there is any, please tell me.

  • 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-05T09:16:07+00:00Added an answer on June 5, 2026 at 9:16 am

    If Point is a struct, you’ll need to have a class that contains OutPoint.

    class OutPointContainer { //Please, think of a better name :)
        public Point OutPoint{ get; set; }
    }
    
    class Tool
    {
    public Action Select;
    public Action Cancel;
    public Point position;
    
    public Tool(OutPointContainer outPointContainer)
    {
        Select = () => outPoint.OutPoint = position;
    }
    
    public void Update(Point newPosition)
    {
    position = newPosition
    }
    public void UpdateKey(Keys k, bool IsPress)
    {
    //Invoke Select/Cancel when press some keys
    }
    
    }
    

    Later, you always use the Point from OutPointContainer.OutPoint

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to encapsulate the following query into a method that returns a query
I want to have a dynamic webpage that automaticly updates some information, this information
Want to play a file that on path like this /var/spool/sound/dog.wav present on server.
I have a class that I want to put factory methods on to spit
I want to create a method that allows me to change arbitrary properties of
I want to encapsulate MessageBox Class inside another Class and pass this object to
basically I want to encapsulate a simple component from code that I already have.
I have a method that I want to access from only one method because
I'm writing an RTS game, and I want to encapsulate user actions into commands.
Want to use signal when follow() function called in UserProfile. I've written signal which

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.