110,567
社区成员
发帖
与我相关
我的任务
分享
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.");
}
}