2012年5月13日日曜日

開発環境

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

独習C# 第3版 ハーバート・シルト (著) エディフィストラーニング株式会社 矢嶋聡 (監修, 翻訳) の第15章(C#4.0の新機能)の理解度チェック1、2、3を解いてみる。

1.

実引数を仮引数に渡す2つの方法。

  1. 位置指定引数(positional argument)
  2. 名前付き引数

2.

コード

using System;

class Tester
{
    static int CalcPrice(
        int height = 1, int width = 1,
        int depth = 1, int quantity = 0)
    {
        return height * width * depth * quantity;
    }

    public void Run()
    {
        Console.WriteLine(
            Tester.CalcPrice(width: 20, quantity: 30));
    }
    static void Main()
    {
        Tester t = new Tester();
        t.Run();
    }
}

入出力結果(Console Window)

600
続行するには何かキーを押してください . . .

3.

問題のメソッドを問題のように呼び出すことはできない。省略可能ではない仮引数、principalが実引数で指定されていないから。

0 コメント:

コメントを投稿