Kamimura's blog
プログラミング(Python、Perl、C、Go、JavaScript)、数学、読書…
ほしい物リスト
2010年8月2日月曜日
プログラミング学習の記録 270.1 "初めてのC# 第2版"の第7章(メソッド)の8.5(練習問題)
開発環境
Microsoft Windows 7 Home Premium (OS)
Microsoft Visual C# 2010 Express Edition (IDE)
言語: C#
"初めてのC# 第2版"のp.138, 第8章(メソッド)の8.5(練習問題)、練習 8-1, 2, 3を解いてみる。
練習 8-1
using System; class Tester { public void Run() { int n = 10; float m = 1.2f; Console.WriteLine("{0}*2={1}", n, Double(n)); Console.WriteLine("{0}*2={1}", m, Double(m)); } static int Double(int n) { return n * 2; } static float Double(float n) { return n * 2; } static void Main() { Tester test = new Tester(); test.Run(); } }
練習 8-2
using System; class Tester { public void Run() { int n = 10; int doubleN = 0; int tripleN = 0; DoubleAndTriple(n, ref doubleN, ref tripleN); Console.WriteLine("{0}*2={1}", n, doubleN); Console.WriteLine("{0}*3={1}", n, tripleN); } static void DoubleAndTriple(int n, ref int doubleN, ref int tripleN) { doubleN = n * 2; tripleN = n * 3; } static void Main() { Tester test = new Tester(); test.Run(); } }
練習 8-3
using System; class Tester { public void Run() { int n = 10; int doubleN; int tripleN; DoubleAndTriple(n, out doubleN, out tripleN); Console.WriteLine("{0}*2={1}", n, doubleN); Console.WriteLine("{0}*3={1}", n, tripleN); } static void DoubleAndTriple(int n, out int doubleN, out int tripleN) { doubleN = n * 2; tripleN = n * 3; } static void Main() { Tester test = new Tester(); test.Run(); } }
0 コメント:
コメントを投稿
次の投稿
前の投稿
ホーム
コメントの投稿(Atom)
0 コメント:
コメントを投稿