using System;
using System.Collections.Generic;
using System.Text;

namespace 泛型类
{
//泛型类
class ClassA
{
private T a;
private T b;

    public ClassA (T a,T b)
    {
        this.a = a;
        this.b = b;
    }

    public string Show()
    {
        return a +" "+ b;
    }

}

}

/*using System;

namespace 泛型类
{
class Program
{
public static string GetSum<T,T2,T3>(T a,T b)//泛型方法,可指定多个泛型,在调用是指定类型
{
return a +" "+ b;
}

    static void Main(string[] args)
    {

        var o1 = new ClassA <int>(22,53);

        Console.WriteLine(  o1.Show());

        var s1 = new ClassA<string>("wei", "715");

        Console.WriteLine(s1.Show());

        Console.WriteLine(GetSum <int ,int ,int >(123,314));//有多个泛型时,调用要指定所有类型
        Console.WriteLine( GetSum<string ,string ,string > ("da","werr"));


        //Console.ReadKey();

    }
}

}*/
using System;
using System.Collections.Generic;

//泛型委托
delegate T NumberChanger(T n);//返回值与参数类型为T
namespace GenericDelegateAppl
{
class TestDelegate
{
static int num = 10;
public static int AddNum(int p)
{
num += p;
return num;
}

    public static int MultNum(int q)
    {
        num *= q;
        return num;
    }
    public static int getNum()
    {
        return num;
    }

    static void Main(string[] args)
    {
        // 创建委托实例
        //NumberChanger<int> nc1 = new NumberChanger<int>(AddNum);
        NumberChanger<int> nc1 = AddNum;//上一行简写
        NumberChanger<int> nc2 = new NumberChanger<int>(MultNum);
        // 使用委托对象调用方法
        nc1(25);
        Console.WriteLine("Value of Num: {0}", getNum());
        nc2(5);
        Console.WriteLine("Value of Num: {0}", getNum());
        Console.ReadKey();
    }
}

}