C#汎用メソッド
4100 ワード
static void Main(string[] args) {
TestClass cls = new TestClass(); cls.GetType("123");
Student stu=new汎用メソッド.Student();stu.Name="王五";stu.Age=23;
//使用してこそタイプcls.GetParam(stu);
Console.ReadKey();
}
public class TestClass {
転載先:https://www.cnblogs.com/yang12311/p/10500106.html
TestClass cls = new TestClass(); cls.GetType("123");
Student stu=new汎用メソッド.Student();stu.Name="王五";stu.Age=23;
//使用してこそタイプcls.GetParam(stu);
Console.ReadKey();
}
public class TestClass {
///
/// object , ,
///
///
public void GetType(object tParam)
{
// tParam ,
Console.WriteLine(" :"+tParam.GetType());
}
///
/// ,T , , T People ,
///
///
///
public void ShowGeneric(T tParam) where T :People
{
Console.WriteLine(" :" + tParam.GetType() + " , :" + tParam.Name);
//SayHi() People
tParam.SayHi();
}
///
///
///
///
///
public void GetParam(T tParam)
{
// is
if (tParam is Student)
{
Student stu = tParam as Student;
Console.WriteLine(" :" + tParam.GetType() + " " + stu.Name);
}
else
Console.WriteLine(" :" + tParam.GetType());
}
}
転載先:https://www.cnblogs.com/yang12311/p/10500106.html