c#反射 判断 是否是自定义类而不是基本类型(如bool,int等)

2025-03-25 07:43:11
推荐回答(1个)
回答1:

你好,可以使用如下方式判断:

Type t = typeof(yourType); // yourType指的是你要判断的类型
if (t.IsPrimitive) // 为true,表示是.net的原生类型,即基础类型,注意string类型,自定义的struct,class不是原生类型
{
}
else
{

}