2009年12月11日金曜日

Format静的メソッドを使用し書式を指定し文字列データをFormatする。
using System;

class MainClass
{
    static void Main()
    {
        // string型、int型の変数を宣言
        string one = "1";
        int n = 2;
        string three = "3";
        int n1 = 4;
        string five = "5";
        int n2 = 15;

        /* Formatを使用し暗黙的にint型を文字列に変換して
         * 出力する */
        // 出力値:1+2+3+4+5=15
        Console.WriteLine(string.Format("{0}+{1}+{2}+{3}+{4}={5}",
            one, n, three,n1,five,n2));
    }
}

0 コメント:

コメントを投稿