fork(1) download
  1. using System;
  2.  
  3. public class MyClassContainer
  4. {
  5. private MyClass MyClass_Instance;
  6.  
  7. public void DemonstrateAccessLevels()
  8. {
  9. MyClass_Instance = new MyClass();
  10.  
  11. MyClass_Instance.SomePublicMethod();
  12.  
  13. MyClass_Instance.SomeInternalMethod();
  14.  
  15. // we can't access protected or private methods of MyClass from MyClassContainer
  16. //
  17. //error CS0122: `MyClass.SomeProtectedMethod()' is inaccessible due to its protection level
  18. //MyClass_Instance.SomeProtectedMethod();
  19.  
  20. //error CS0122: `MyClass.SomePrivateMethod()' is inaccessible due to its protection level
  21. //MyClass_Instance.SomePrivateMethod();
  22. }
  23. }
  24.  
  25. public class MyClass
  26. {
  27. private void SomePrivateMethod()
  28. {
  29. Console.WriteLine("Some Private Method");
  30. }
  31.  
  32. protected void SomeProtectedMethod()
  33. {
  34. Console.WriteLine("Some Protected Method");
  35. }
  36.  
  37. internal void SomeInternalMethod()
  38. {
  39. Console.WriteLine("Some Internal Method");
  40. }
  41.  
  42. public void SomePublicMethod()
  43. {
  44. Console.WriteLine("Some Public Method");
  45. }
  46. }
  47.  
  48. public class Test
  49. {
  50. public static void Main()
  51. {
  52. MyClassContainer testContainer = new MyClassContainer();
  53.  
  54. testContainer.DemonstrateAccessLevels();
  55. }
  56. }
Success #stdin #stdout 0.03s 23872KB
stdin
Standard input is empty
stdout
Some Public Method
Some Internal Method