Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Parent can Read
- public class Parent
- {
- public string Read(){ /*reads here*/ };
- }
- // Child need Info
- public class Child
- {
- private string information;
- // declare a Delegate
- delegate string GetInfo();
- // use an instance of the declared Delegate
- public GetInfo GetMeInformation;
- public void ObtainInfo()
- {
- // Child will use the Parent capabilities via the Delegate
- information = GetMeInformation();
- }
- }
- Parent Peter = new Parent();
- Child Johny = new Child();
- // Tell Johny from where to obtain info
- Johny.GetMeInformation = Peter.Read;
- Johny.ObtainInfo(); // here Johny 'asks' Peter to read
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement