2012年5月18日金曜日

開発環境

  • 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)の 第3章(C#言語の基礎)3.10(練習問題)、問題3-2を解いてみる。

問題3-2.

コード

using System;

namespace Sample
{
    class Tester
    {
        public void Run()
        {
            int a = 10;
            float b = 1.2f;
            double c = 12345.6789;
            char d = 'c';
            Console.WriteLine(
                "int型 {0}\nfloat型 {1}\ndouble型 {2}\nchar型 {3}",
                a, b, c, d);
            a = 20;
            b = 2.1f;
            c = 9876.54321;
            d = 'd';
            Console.WriteLine("変更後");
            Console.WriteLine(
                "int型 {0}\nfloat型 {1}\ndouble型 {2}\nchar型 {3}",
                a, b, c, d);
        }
        static void Main()
        {
            Tester t = new Tester();
            t.Run();
        }
    }
}

入出力結果(Console Window)

int型 10
float型 1.2
double型 12345.6789
char型 c
変更後
int型 20
float型 2.1
double型 9876.54321
char型 d
続行するには何かキーを押してください . . .

0 コメント:

コメントを投稿