2. About me
• Tomo Mizoe
• CEO & Founder of July Inc.
• http://www.july.co.jp
• Twitter: @tmizoe
• Microsoft Certified Trainer
• Microsoft Certified Solution Developer
• Windows Store Apps using HTML5 and JavaScript
• Web Applications
41. while
• 書き方はPHPと同じ
• break, continueも同じ
int i = 0;
while (i < 10)
{
Console.WriteLine(i);
i++;
}
int j = 0;
while (true)
{
Console.WriteLine(j);
j++;
if(j < 10)
{
break;
}
}
58. クラスとは?
• クラス = 設計図
Book
title
price
author
isbn
getTaxIncludedPrice()
getTax()
publishedDate
publisher
フィールド(メンバ変数)
メソッド
59. クラスを定義してみよう
フィールド
メソッド
class Book
{
public string title;
public string author;
public DateTime publishedDate;
public int price;
public const double taxRatio = 0.08; //定数
public int getTax()
{
return (int)(price * taxRatio);
}
public int getTaxIncludedPrice()
{
return price + getTax();
}
}
64. 継承
• 既存のクラスを拡張する
// 月刊誌クラス
class Magazine : Book
{
public int month; // x月号
public string getMonth()
{
return month + "月号";
}
}
// 文庫クラス
class Novel : Book
{
public string series; // x文庫
}
71. コンストラクタ
class Book
{
public string title;
public string author;
public DateTime publishedDate;
public int price;
public const double taxRatio = 0.08;
//引数なしでインスタンス化した場合に実行される
public Book()
{
}
//引数ありでインスタンス化した場合に実行される
public Book(string title, string author, DateTime publishedDate, int price)
{
this.title = title;
this.author = author;
this.publishedDate = publishedDate;
this.price = price;
}
コンストラクタ:new のときに自動実行されるメソッド