msg 类的定义
using System; using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{ public class user<T> where T :class,new()
{
public string getClassName()
{ return typeof(T).Name.ToString();
}
}
}
user<T> 类的定义
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{ public class user<T> where T :class,new()
{
public string getClassName()
{ return typeof(T).Name.ToString();
}
}
}
模拟场景类的定义
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
// Console.WriteLine( typeof(user).Name.ToString());
user<msg> um = new user<msg>();
Console.WriteLine("msg.fullName="+typeof(msg).FullName);
Console.WriteLine("um.GetType="+ um.GetType().ToString());
Console.WriteLine("um<T> T.ClassName="+um.getClassName());
Console.ReadKey();
}
}
}