Demonstrates deriving a new class from a base class in another assembly : Class Deriving « Class Interface « C# / C Sharp






Demonstrates deriving a new class from a base class in another assembly

Demonstrates deriving a new class from a base class in another assembly
/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa

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

//
//  Access1.cs - demonstrates deriving a new class from a base class in
//               another assembly. Also demonstrates how a derived class
//               may provide a public property to expose a protected member
//               of a base class.
//
//               Compile this program with the following command line:
//                   C:>csc /r:access.exe Access1.cs
//
namespace nsAccess
{
    using System;
    
    public class Access1
    {
        static public void Main ()
        {
            clsDerived derived = new clsDerived ();
            derived.AccessIt = 42;
            derived.ShowField ();
        }
    }
//
// Derive a class from the base class and give it a public
// property to access the private field in the base class
    class clsDerived : clsBase
    {
        public int AccessIt
        {
            get {return (Private);}
            set {Private = value;}
        }
    }
    public class clsBase
    {
        private int m_Private;
        protected int Private
        {
            get {return (m_Private);}
            set {m_Private = value;}
        }
        public void ShowField ()
        {
            Console.WriteLine ("The value of private field m_Private is " + m_Private);
        }
    }
    
}


           
       








Related examples in the same category

1.the overridden methods of the System.Object class