class Program
{
static void Main(string[] args)
{
var helloList = new ISayHello[]
{
new CSharpHello(), new VBnetHello(),
}; foreach (var sayHello in helloList)
{
sayHello.Say();
}
Console.ReadLine();
}
}
▸ 実行ボタンで結果を表示
Source収録記事
この snippet は記事の「配列をぶん回して実行」セクションに登場する。コードの前後の文脈・ハマりどころの解説は記事本文で。
同じ記事から
11 件namespace InterfaceExample { public interface ISayHello {未収録
まずはInterfaceを定義
#a3072e9f21f7
using System;namespace InterfaceExample { public class CSharpHello : ISayHello {
▶ 実行可
Interfaceを継承したクラスを定義
#9b430c6ee487
using System;namespace InterfaceExample { public class VBnetHello : ISayHello {
▶ 実行可
Interfaceを継承したクラスを定義
#950dfa8ee749
namespace InterfaceExample { class Program {未収録
Interfaceの配列を定義
#25928746ad18
using System;namespace InterfaceExample { public class FreeHello : ISayHello {
▶ 実行可
自由にHelloというクラスを作ってみる
#13efe9b65211
namespace InterfaceExample { class Program {
▶ 実行可
自由にHelloというクラスを作ってみる
#12ac9226ce1e
