Demonstrates the use of a simple interface : Interface « Class Interface « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » Class Interface » InterfaceScreenshots 
Demonstrates the use of a simple interface
Demonstrates the use of a simple interface

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

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/
// IntrFace.cs -- demonstrates the use of a simple interface
//
//                Compile this program with the following command line:
//                    C:>csc IntrFace.cs
using System;

namespace nsInterface
{
    interface IPlane
    {
        double Area
        {
            get;
        }
    }
    interface ISolid
    {
        double Volume
        {
            get;
        }
    }

    class clsCircle : IPlane
    {
        public clsCircle (double radius)
        {
            m_Radius = radius;
        }
        public double Area
        {
            get {return (3.14159 * m_Radius * m_Radius);}
        }
        private double m_Radius;


        public override string ToString ()
        {
            return ("Area = " + Area);
        }
    }
    class clsSphere : IPlane, ISolid
    {
        public clsSphere (double radius)
        {
            m_Radius = radius;
        }
        public double Area
        {
            get {return (3.14159 * m_Radius * m_Radius);}
        }
        public double Volume
        {
            get {return (3.14159 * m_Radius * m_Radius * m_Radius / 3);}
        }
        private double m_Radius;

        public override string ToString ()
        {
            return ("Area = " + Area + ", " "Volume = " + Volume);
        }
    }

    public class IntrFace
    {
        static public void Main ()
        {
            clsCircle circle = new clsCircle (14.2);
            clsSphere sphere = new clsSphere (16.8);
            Console.WriteLine ("For the circle: " + circle);
            Console.WriteLine ("For the sphere: " + sphere);
        }
    }
}



           
       
Related examples in the same category
1.Interface with method name conflicts
2.Demonstrate the ByTwos interfaceDemonstrate the ByTwos interface
3.Demonstrate the ByTwos interface 2Demonstrate the ByTwos interface 2
4.Use a property in an interfaceUse a property in an interface
5.Add an indexer in an interfaceAdd an indexer in an interface
6.One interface can inherit anotherOne interface can inherit another
7.Explicitly implement an interface memberExplicitly implement an interface member
8.Use explicit implementation to remove ambiguityUse explicit implementation to remove ambiguity
9.Two class inherit one interfaceTwo class inherit one interface
10.Using interface 3Using interface 3
11.illustrates interfacesillustrates interfaces
12.illustrates implementing multiple interfacesillustrates implementing multiple interfaces
13.illustrates inheriting from a class and implementing multiple interfacesillustrates inheriting from a class and implementing multiple interfaces
14.illustrates casting an object to an interfaceillustrates casting an object to an interface
15.illustrates deriving an interface from one interfaceillustrates deriving an interface from one interface
16.illustrates deriving an interface from multiple interfacesillustrates deriving an interface from multiple interfaces
17.illustrates an explicit interface member implementationillustrates an explicit interface member implementation
18.illustrates interface member hidingillustrates interface member hiding
19.Interface demoInterface demo
20.Interface demo: implements two interfacesInterface demo: implements two interfaces
21.Interface castingInterface casting
22.Overriding InterfacesOverriding Interfaces
23.Overriding Interfaces: Tester Overriding InterfacesAsOverriding Interfaces: Tester Overriding InterfacesAs
24.A safe method of determining whether a class implements a particular interfaceA safe method of determining whether a class implements a particular interface
25.Interfaces:Working with InterfacesInterfaces:Working with Interfaces
26.Reimplementation of Interfaces
27.Interface with event
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.