開発環境
- OS: Windows 10 Pro
- IDE(統合開発環境): Visual Studio Community 2017
Head First C# ―頭とからだで覚えるC#の基本 (Andrew Stellman (著)、Jennifer Greene (著)、佐藤 嘉一 (監修, 監修)、木下 哲也 (翻訳)、オライリージャパン)の4章(型と参照 - 10時です。データがどこにあるか分かりますか?)、エクササイズ(p. 145)を取り組んでみる。
コード
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp9
{
public partial class Form1 : Form
{
private Elephant lucinda;
private Elephant lloyd;
public Form1()
{
InitializeComponent();
lucinda = new Elephant() { name = "ルシンダ", earSize = 85 };
lloyd = new Elephant() { name = "リロイド", earSize = 100 };
}
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 t = lloyd;
lloyd = lucinda;
lucinda = t;
MessageBox.Show("オブジェクトを交換しました。");
}
}
class Elephant
{
public string name;
public int earSize;
public void whoAmI()
{
MessageBox.Show(
"私の耳の大きさは" + earSize + "cmです。",
name + "が言った・・・");
}
}
}
0 コメント:
コメントを投稿