Interfaces:Working with Interfaces : Interface « Language Basics « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Collections Data Structure
3. Components
4. Database ADO.net
5. Development Class
6. Event
7. File Stream
8. GUI Windows Form
9. Language Basics
10. Network
11. Office
12. Regular Expressions
13. Services Event
14. Thread
15. Web Services
16. Windows
17. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
C# / C Sharp » Language Basics » InterfaceScreenshots 
Interfaces:Working with Interfaces
Interfaces:Working with Interfaces


/*
A Programmer's Introduction to C# (Second Edition)
by Eric Gunnerson

Publisher: Apress  L.P.
ISBN: 1-893115-62-3
*/

// 10 - Interfaces\Working with Interfaces
// copyright 2000 Eric Gunnerson
using System;

public class WorkingwithInterfaces
{
    public static void Main()
    {
        DiagramObject[] dArray = new DiagramObject[100];
        
        dArray[0new DiagramObject();
        dArray[1new TextObject("Text Dude");
        dArray[2new TextObject("Text Backup");
        
        // array gets initialized here, with classes that
        // derive from DiagramObject. Some of them implement
        // IScalable.
        
        foreach (DiagramObject d in dArray)
        {
            if (d is IScalable)
            {
                IScalable scalable = (IScalabled;
                scalable.ScaleX(0.1F);
                scalable.ScaleY(10.0F);
            }
        }
    }
}

interface IScalable
{
    void ScaleX(float factor);
    void ScaleY(float factor);
}
public class DiagramObject
{
    public DiagramObject() {}
}
public class TextObject: DiagramObject, IScalable
{
    public TextObject(string text)
    {
        this.text = text;
    }
    // implementing IScalable.ScaleX()
    public void ScaleX(float factor)
    {
        Console.WriteLine("ScaleX: {0} {1}", text, factor);
        // scale the object here.
    }
    
    // implementing IScalable.ScaleY()
    public void ScaleY(float factor)
    {
        Console.WriteLine("ScaleY: {0} {1}", text, factor);
        // scale the object here.
    }
    
    private string text;
}

           
       
Related examples in the same category
1. Demonstrate the ByTwos interfaceDemonstrate the ByTwos interface
2. Demonstrate the ByTwos interface 2Demonstrate the ByTwos interface 2
3. Use a property in an interfaceUse a property in an interface
4. Add an indexer in an interfaceAdd an indexer in an interface
5. One interface can inherit anotherOne interface can inherit another
6. Explicitly implement an interface memberExplicitly implement an interface member
7. Use explicit implementation to remove ambiguityUse explicit implementation to remove ambiguity
8. Two class inherit one interfaceTwo class inherit one interface
9. Using interface 3Using interface 3
10. illustrates interfacesillustrates interfaces
11. illustrates implementing multiple interfacesillustrates implementing multiple interfaces
12. illustrates inheriting from a class and implementing multiple interfacesillustrates inheriting from a class and implementing multiple interfaces
13. illustrates casting an object to an interfaceillustrates casting an object to an interface
14. illustrates deriving an interface from one interfaceillustrates deriving an interface from one interface
15. illustrates deriving an interface from multiple interfacesillustrates deriving an interface from multiple interfaces
16. illustrates an explicit interface member implementationillustrates an explicit interface member implementation
17. illustrates interface member hidingillustrates interface member hiding
18. Demonstrates the use of a simple interfaceDemonstrates the use of a simple interface
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
ww_w__.j___ava___2___s_.co___m_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.