2009年12月23日水曜日

1つのクラスで2つのInterface(Interface1,Interface2)を実装してみる。

using System;


interface Interface1
{
    void method1(int a);
}
interface Interface2
{
    void method2(int b);
}
// Interface1,2を実装
class TestClass : Interface1, Interface2
{
    public void method1(int a)
    {
        Console.WriteLine(a);
    }
    public void method2(int b)
    {
        Console.WriteLine(b);
    }
}
class MainClass
{
    static void Main()
    {
        TestClass test = new TestClass();
        // 出力値:1
        test.method1(1);
        // 出力値:2
        test.method2(2);
    }
}

0 コメント:

コメントを投稿