Is there a function to check if an object is a builtin data type?

前端 未结 3 2009
日久生厌
日久生厌 2020-12-10 18:58

I would like to see if an object is a builtin data type in C#

I don\'t want to check against all of them if possible.
That is, I don\'t want to do this:

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-10 19:28

    I think this is one of the best possibilies:

    private static bool IsBulitinType(Type type)
    {
        return (type == typeof(object) || Type.GetTypeCode(type) != TypeCode.Object);
    }
    

提交回复
热议问题