Head First C#
頭とからだで覚えるC#の基本
(オライリージャパン)
Andrew Stellman (著), Jennifer Green (著)
佐藤 嘉一 (監修), 木下 哲也 (翻訳)
開発環境
- Microsoft Windows 8.1 Pro (VMware Fusion 6, OS X Mavericks - Apple) (OS)
- C# (プログラミング言語)
- Microsoft Visual Studio Express 2013 for Windows Desktop (統合開発環境, IDE)
Head First C#―頭とからだで覚えるC#の基本 (Andrew Stellman (著)、Jennifer Green (著)、佐藤 嘉一 (監修)、木下 哲也 (翻訳)、オライリージャパン)の4章(型と参照: 10時です。データがどこにあるかわかりますか?)、エクササイズ(p.145)を解いてみる。
エクササイズ(p.145)
コード
Form1.cs
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Elephant lucinda;
Elephant lloyd;
public Form1()
{
lucinda = new Elephant() { Name = "ルシンダ", EarSize = 85 };
lloyd = new Elephant() { Name = "リロイド", EarSize = 100 };
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
lloyd.WhoAmI();
}
private void button2_Click(object sender, EventArgs e)
{
lucinda.WhoAmI();
}
private void button3_Click(object sender, EventArgs e)
{
Elephant temp = lucinda;
lucinda = lloyd;
lloyd = temp;
MessageBox.Show("オブジェクトを交換しました", "交換");
}
}
class Elephant
{
public string Name;
public int EarSize;
public void WhoAmI()
{
MessageBox.Show("私の目の大きさは" + EarSize + "cmです。", Name + "が言った…");
}
}
}
0 コメント:
コメントを投稿