Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.66 KB | None | 0 0
  1. // Parent can Read
  2. public class Parent
  3. {
  4.     public string Read(){ /*reads here*/ };
  5. }
  6.  
  7. // Child need Info
  8. public class Child
  9. {
  10.     private string information;
  11.     // declare a Delegate
  12.     delegate string GetInfo();
  13.     // use an instance of the declared Delegate
  14.     public GetInfo GetMeInformation;
  15.  
  16.     public void ObtainInfo()
  17.     {
  18.         // Child will use the Parent capabilities via the Delegate
  19.         information = GetMeInformation();
  20.     }
  21. }
  22.  
  23.  
  24. Parent Peter = new Parent();
  25. Child Johny = new Child();
  26.  
  27. // Tell Johny from where to obtain info
  28. Johny.GetMeInformation = Peter.Read;
  29.  
  30. Johny.ObtainInfo(); // here Johny 'asks' Peter to read
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement