using System;namespace InterfaceExample
{
public class FreeHello : ISayHello
{
private string _helloItem;
public FreeHello(string helloItem)
{
_helloItem = helloItem;
}
public void Say()
{
Console.WriteLine($@"Hello {_helloItem}");
}
}
▸ 実行ボタンで結果を表示
Source収録記事
この snippet は記事の「自由にHelloというクラスを作ってみる」セクションに登場する。コードの前後の文脈・ハマりどころの解説は記事本文で。
同じ記事から
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
class Program { static void Main(string[] args) {
▶ 実行可
配列をぶん回して実行
#e9039e6a9d95
namespace InterfaceExample { class Program {
▶ 実行可
自由にHelloというクラスを作ってみる
#12ac9226ce1e
