using System;
interface Interface
{
void Display(string a);
}
interface Interface1
{
// Interfaceと同じメソッド
void Display(string b);
}
// インターフェイスの実装
class TestClass : Interface, Interface1
{
public void Display(string a)
{
Console.WriteLine("Interface10 : " + a);
}
/* 明示的なインターフェイスの宣言
publicキーワードは不要
publicを付けるとエラーになる */
void Interface.Display(string a)
{
Console.WriteLine("Interface : " + a);
}
// 明示的なインターフェイスの宣言
void Interface1.Display(string a)
{
Console.WriteLine("Interface1 : " + a);
}
}
class MainClass
{
static void Main()
{
TestClass t = new TestClass();
t.Display("10"); // 出力値:Interface 10 : 10
// インターフェイスに変換
Interface i = (Interface)t;
i.Display("0"); // 出力値:Interface : 0
// インターフェイスに変換
Interface1 i1 = (Interface1)t;
i1.Display("1"); // 出力値:Interface1 : 1
}
}
1日に書くソースコードの量が増えてきたので、今日から1つのプログラムごとに1つの投稿という形にしていくことにしました。番号は"日別.プログラム別"という風にしていきたいと思います。
0 コメント:
コメントを投稿