「C#入門」インターフェースのサンプル
書式
public interface インターフェース名
public class クラス名:インターフェース名
使用例
using System;
namespace ProjectTest
{
//インターフェースの定義
public interface InterCft
{
//抽象メソッドの定義
void testFunc();
}
//インターフェースの実装
public class TestDemo: InterCft
{
void InterCft.testFunc()
{
Console.WriteLine("this is a test 12345");
}
}
class Kdfc
{
static void Main()
{
//インターフェース
InterCft ipa = new TestDemo();
ipa.testFunc();
}
}
}
using System;
namespace ProjectTest
{
//インターフェースの定義
public interface InterCft
{
//抽象メソッドの定義
void testFunc();
}
//インターフェースの実装
public class TestDemo: InterCft
{
void InterCft.testFunc()
{
Console.WriteLine("this is a test 12345");
}
}
class Kdfc
{
static void Main()
{
//インターフェース
InterCft ipa = new TestDemo();
ipa.testFunc();
}
}
}
using System; namespace ProjectTest { //インターフェースの定義 public interface InterCft { //抽象メソッドの定義 void testFunc(); } //インターフェースの実装 public class TestDemo: InterCft { void InterCft.testFunc() { Console.WriteLine("this is a test 12345"); } } class Kdfc { static void Main() { //インターフェース InterCft ipa = new TestDemo(); ipa.testFunc(); } } }
実行結果
this is a test 12345