Private field and public Property in inheritance : Class Inheritance : Class Interface C# Source Code


Custom Search

C# Source Code » Class Interface » Class Inheritance »

 

Private field and public Property in inheritance









    

/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/

namespace nsInherit
{
    using System;
    
    public class clsMainInherit
    {
        static public void Main ()
        {
            clsDerived derived = new clsDerived();
            derived.Property = 42;
            derived.ShowField();
        }
    }
//
// Define a base class with a private field and a public Property
    class clsBase
    {
        private int m_Field;
        public int Property
        {
            get {return (m_Field);}
            set {m_Field = value;}
        }
        public void ShowField ()
        {
            Console.WriteLine ("The value of m_Field is " + m_Field);
        }
    }
//
// Define a derived class that inherits from the clsBase
    class clsDerived : clsBase
    {
// For now, the derived class needs no members
    }
}


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Class Interface
» Class Inheritance