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.157)を解いてみる。
コードマグネット(p.157)
コード
Form1.cs
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
String result = "";
String[] islands = new String[4];
int[] index = new int[4];
int y = 0;
islands[0] = "バミューダ";
islands[1] = "フィジー";
islands[2] = "アゾレス";
islands[3] = "コスメル";
index[0] = 1;
index[1] = 3;
index[2] = 0;
index[3] = 2;
int refNum;
while (y < 4)
{
result += "\n島 = ";
refNum = index[y];
result += islands[refNum];
y = y + 1;
}
MessageBox.Show(result);
}
}
}
0 コメント:
コメントを投稿