魔法使いとC#のてんぷら

魔法使いと黒猫のウィズをリリース直後からやっているてんぷらです。
C#クイズスタート☆
※答えは **A.** の後ろをハイライト表示

# Q.1
```csharp:
enum Status : int
{
    Fire    = 1,
    Water   = 2,
    Thunder = 3
}

void Main()
{
    string value = Status.Water.ToString();
}
```
`value` の値は？

**A.<font color="white">Water</font>**

# Q.2
```csharp:
using System.Linq;

class Program
{
    void Main()
    {
        object data = "3,5,7,1,9";
        var value = ((string)data).Split(',').Select((no) => int.Parse(no)).ToArray();
    }
}
```
`value` の型は？

**A.<font color="white">int[]</font>**

# Q.3
```csharp:
class Program
{
    public static const int X = 1; // (1)
    public readonly int Y = 2;     // (2)

    public Program()
    {
        Y = 3; // (3)
    }
}
```
エラーになるのは (1)～(3) のうちどれ？

**A.<font color="white">(1)</font>**

# Q.4
```csharp:
public void Main()
{
    var num0  = new Number(1);
    var num1  = new Number(1);
    int value = (num0 + num0).Num;
}

struct Number
{
    public int Num { get; private set; }

    public Number(int num)
    {
        Num = num;
    }

    public static Number operator +(Number num0, Number num1)
    {
        return new Number((num0.Num + num1.Num) * 2);
    }
}
```
value の値は？

**A.<font color="white">4</font>**

# Q.5
```csharp:
class Program
{
    private Monster monster = new Monster();

    public void Main()
    {
        monster.Id = 3;
    }
}

class Monster
{
    private int id = 0;
    private string name = "";

    public int Id
    {
        get { return id; }
        set 
        {
            id = value;
            Name = "Monster_" + id;
        }
    }

    public string Name
    {
        get { return name; }
        set 
        {
            name = value;
            id = 1;
        }
    }
}
```
`Main()` メソッドが呼ばれた後、`id` の値は？

**A.<font color="white">1</font>**

# Q.6
```csharp:
void Main() 
{
    var str = "1";        // (1)
    var num = (int)str;   // (2)
    str = num.ToString(); // (3)
}
```
エラーになるのは (1)～(3) のうちどれ？

**A.<font color="white">(2)</font>**

# Q.7
```csharp:
class BaseProgram
{
    protected int value = 0;

    protected virtual void Do()
    {
        value++;
    }
}

class Program : BaseProgram
{
    public void Main()
    {
        Do();
    }

    protected override void Do()
    {
        value++;
    }
}
```
`Main()` メソッドが呼ばれた後、`value` の値は？

**A.<font color="white">1</font>**

# Q.8
```csharp:
public void Main()
{
    Func<int[], int> main = null;
    main = (args) =>
    {
        Func<int, int, int, int> parupunte = null;
        parupunte = (idx, arg, res) =>
        {
            res += (idx != 1) ? arg : (arg + arg);
            return res;
        };

        int result = 0;
        for (int i = 0; i < args.Length; i++)
        {
            result = parupunte(i, args[i], result);
        }
        return result;
    };

    int value = main(new int[] { 1, 2, 3 });
}
```
`value` の値は？

**A.<font color="white">8</font>**

# Q.9
```csharp:
class Program
{
    public void Main()
    {
        int value = 
            new Data(1)
            .Add(3)
            .Mul(2)
            .Sub(1)
            .Div(3)
            .Mul(5)
            .Sub(22)
            .Add(14)
            .Mul(8)
            .Sub(17)
            .Mul(2)
            .Div(4)
            .Answer();
    }
}

class Data
{
    private int num = 0;

    public Data(int num)
    {
        this.num = num;
    }

    public Data Add(int add)
    {
        num += add;
        return this;
    }

    public Data Sub(int sub)
    {
        num -= sub;
        return this;
    }

    public Data Mul(int mul)
    {
        num *= mul;
        return this;
    }

    public Data Div(int div)
    {
        num /= div;
        return this;
    }

    public int Answer()
    {
        num *= 0;
        return num;
    }
}
```
value の値は？

**A.<font color="white">0</font>**

# Q.10
```csharp:
using System.Linq;

class Program
{
    public void Main()
    {
        int[] data = { 1, 2, 3, 4, 5 };
        var value = data.Where((a) => (a > 1 && ((a % 2) == 1))).OrderByDescending((a) => a).Select((a) => a.ToString()).Aggregate((a, b) => a + "_" + b);
    }
}
```
value の値は？

**A.<font color="white">5_3</font>**