fork download
  1. using System;
  2.  
  3. public abstract class MenuItem
  4. {
  5. protected string m_Title;
  6. }
  7.  
  8. public class ContainerItem : MenuItem
  9. {
  10. void Foo()
  11. {
  12. var derivedItem = new ContainerItem();
  13. derivedItem.m_Title = "test"; // works fine
  14.  
  15. var baseItem = (MenuItem)derivedItem;
  16. baseItem.m_Title = "test"; // compiler error!
  17. }
  18. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(16,18): error CS1540: Cannot access protected member `MenuItem.m_Title' via a qualifier of type `MenuItem'. The qualifier must be of type `ContainerItem' or derived from it
prog.cs(5,22): (Location of the symbol related to previous error)
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty