日期:2014-05-17 浏览次数:21073 次
typeof(class).GetMethoc("f").MakeGenericMethod(dt.GetType()).Invoke(null,new Ojbect[]{dt});
static void Main(string[] args)
{
Student stu = new Student();
Say(stu);//I'm student.
Teacher tea = new Teacher();
Say(tea);//I'm teacher.
Say<Student>();//I'm student.
Say<Teacher>();//I'm teacher.
}
static void Say(dynamic obj)
{
obj.Say();
}
static void Say<T>()
{
dynamic obj = Activator.CreateInstance(typeof(T));
obj.Say();
}
struct Student
{
public void Say()
{
Console.WriteLine("I'm student.");
}
}
class Teacher
{
public void Say()
{
Console.WriteLine("I'm teacher.");
}
}