code_junkie

Function which returns reference to be edited in c#

Nov 12th, 2011
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. class foo
  2. {
  3. public int value;
  4. }
  5.  
  6. class bar
  7. {
  8. bar()
  9. {
  10. m_foo = new foo();
  11. m_foo.value = 42;
  12. }
  13. private m_foo;
  14. foo getFoo(){return m_foo;}
  15. }
  16.  
  17. class main
  18. {
  19. int main()
  20. {
  21. bar b = new bar();
  22. b.getFoo().value = 37;
  23. }
  24. }
  25.  
  26. using System;
  27.  
  28. namespace ConsoleApplication1
  29. {
  30. public class foo
  31. {
  32. public int value;
  33. };
  34.  
  35. public class bar
  36. {
  37. public bar()
  38. {
  39. m_foo = new foo();
  40. m_foo.value = 42;
  41. }
  42.  
  43. private foo m_foo;
  44. public foo getFoo() { return m_foo; }
  45. };
  46.  
  47. public class Program
  48. {
  49. public static int Main()
  50. {
  51. bar b = new bar();
  52. b.getFoo().value = 37;
  53. return 0;
  54. }
  55. };
  56. }
  57.  
  58. class bar
  59. {
  60. private m_foo;
  61. bar()
  62. {
  63. m_foo = new foo();
  64. m_foo.value = 42;
  65. }
  66.  
  67.  
  68. foo Foo
  69. {
  70. get { return m_foo;}
  71. }
  72. }
Add Comment
Please, Sign In to add comment