開発環境
- Microsoft Windows 7 Home Premium (OS)
- Microsoft Visual C# 2010 Express Edition (IDE)
- 言語: C#
独習C# 第3版 ハーバート・シルト (著) エディフィストラーニング株式会社 矢嶋聡 (監修, 翻訳) の第4章(Cクラス、オブジェクト、メソッドの基礎)の理解度チェック11、12を解いてみる。
コード
using System; public class MyRect { private int width; private int height; public MyRect(int w, int h) { this.width = w; this.height = h; } public int Area() { return width * height; } } class Tester { public void Run() { int w = 50; int h = 30; MyRect rect = new MyRect(w, h); int x = rect.Area(); Console.WriteLine( "幅{0}、高さ{1}の長方形の面積は{2}", w, h, x); } static void Main() { Tester t = new Tester(); t.Run(); } }
入出力結果(Console Window)
幅50、高さ30の長方形の面積は1500 続行するには何かキーを押してください . . .
0 コメント:
コメントを投稿