2014年6月26日木曜日

開発環境

Head First C#―頭とからだで覚えるC#の基本 (Andrew Stellman (著)、Jennifer Green (著)、佐藤 嘉一 (監修)、木下 哲也 (翻訳)、オライリージャパン)の9章(イベントとデリゲート: 見てないときのコードの動作)、プールパズル(p.400)を解いてみる。

プールパズル(p.400)

コード

Form1.cs

using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.Load += new EventHandler(Car);
            this.Load += new EventHandler(Motorcycle);
        }
        void Towtruck(object sender, EventArgs e)
        {
            Console.Write("is coming ");
        }
        void Motorcycle(object sender, EventArgs e)
        {
            button1.Click += new EventHandler(Bicycle);
        }
        void Bicycle(object sender, EventArgs e)
        {
            Console.WriteLine("to get you!");
        }
        void Car(object sender, EventArgs e)
        {
            button1.Click += new EventHandler(Dumptruck);
            button1.Click += new EventHandler(Towtruck);
        }
        void Dumptruck(object sender, EventArgs e)
        {
            Console.Write("Fingers ");
        }
    }
}

出力

Fingers is coming to get you!

0 コメント:

コメントを投稿