2012年6月19日火曜日

開発環境

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

練習15-1, 2

コード

using System;
using System.Collections.Generic;

namespace Sample
{
    class Tester
    {
        public void Run()
        {
            string s1 = "Hello", s2 = "World",
                s3 = @"Come visit us at http://www.LibertyAssociates.com",
                s41 = s1 + s2, s42 = string.Concat(s1, s2),
                s5 = "world", s61 = string.Copy(s3), s62 = s3;
            string[] strs = { s1, s2, s3, s41, s42, s5, s61, s62 };
            Console.WriteLine("各文字列の3番目の文字");
            foreach (string s in strs)
            {
                Console.WriteLine("{0}: {1}", s, s[2]);
            }
        }
        static void Main()
        {
            Tester t = new Tester();
            t.Run();
        }
    }
}

入出力結果(Console Window)

各文字列の3番目の文字
Hello: l
World: r
Come visit us at http://www.LibertyAssociates.com: m
HelloWorld: l
HelloWorld: l
world: r
Come visit us at http://www.LibertyAssociates.com: m
Come visit us at http://www.LibertyAssociates.com: m
続行するには何かキーを押してください . . .

0 コメント:

コメントを投稿