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

  • Home
  • SEARCH
  • 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 950835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:37:53+00:00 2026-05-15T23:37:53+00:00

In my app, I wanted to let class B get some information from class

  • 0

In my app, I wanted to let class B get some information from class A but as A instantionates B, B has no reference to A (intentionally).
I have never used events for that purpose so I am not sure whether its correct, but it works:

class A
{
 public delegate bool GetFromB();
 public event GetFromB GetDataFromB;
...

//get data from B without having an access to it
bool Result=GetDataFromB();
}

class B
{
A a=new A();
A.GetDataFromB=new A.GetFromB(DO_THAT);

public bool DO_THAT()
{
 ...
return true;     //and that is it, it will return to event caller
}

}
  • 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-05-15T23:37:53+00:00Added an answer on May 15, 2026 at 11:37 pm

    It’ll certainly work, and that approach is used in a few places in the core framework – AssemblyResolve etc. Alternative approaches here:

    • if it is used by a method, pass it into the method as a callback delegate. Same approach, but simply not exposed as an event
    • ditto, but with an interface

    but it’ll work that way. It isn’t unheard of. Code tweaks, though:

    A a=new A();
    a.GetDataFromB=+new A.GetFromB(DO_THAT);
    

    you subscribe on the instance (unless it is static), and need +=, not =.

    Also: consider using Func<bool> rather than declaring your own delegate type.

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

Sidebar

Related Questions

I have built part of my app and wanted to test it out. All
I'm making a tab bar iphone app and I wanted to have an animated
Just wanted to know if overriding UITabBarController would get my app rejected? Is it
I wanted to add some analytics functionnalities to my app so I created an
We have a gwt app that uses jcifs to pull the user name from
I'm developing a first iPhone app for iOS 4.x/5.0 and have some confusions on
Let's say you have an app that declares itself able to handle a system
I have a question about the architecture of a backbone.js web app. Let's say
I posted a question about this earlier, but I have more information now and
If an application has the android.permission.CAMERA, and I wanted my app to block the

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.