2012年5月30日水曜日

開発環境

  • Microsoft Windows 7 Home Premium (OS)
  • Microsoft Visual C# 2010 Express Edition (IDE)
  • 言語: C#

『初めてのC# 第2版』(Jesse Liberty+Brian MacDonald著、日向俊二訳、オライリー・ジャパン、2006年、ISBN978-487311-294-7)の 第8章(メソッド)8.5(練習問題)、練習8-2を解いてみる。

練習8-2.

コード

using System;

namespace Sample
{
    class Tester
    {
        public void DoublerAndTripler(int a, ref int x, ref int y)
        {
            x = 2 * a;
            y = 3 * a;
        }
        public void Run()
        {
            int a = 10;
            int x = 0;
            int y = 0;
            DoublerAndTripler(a, ref x, ref y);
            Console.WriteLine(
                "{0} * 2 = {1}\n{0} * 3 = {2}",
                a, x, y);
        }
        static void Main()
        {
            Tester t = new Tester();
            t.Run();
        }
    }
}

入出力結果(Console Window)

10 * 2 = 20
10 * 3 = 30
続行するには何かキーを押してください . . .

0 コメント:

コメントを投稿