How to compare types

后端 未结 5 1616
半阙折子戏
半阙折子戏 2020-12-13 22:50

Quick question: how to compare a Type type (pun not intended) with another type in C#? I mean, I\'ve a Type typeField and I want to know if it is System.S

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-13 23:33

    http://msdn.microsoft.com/en-us/library/system.type.gettype.aspx

    Console.WriteLine("typeField is a {0}", typeField.GetType());
    

    which would give you something like

    typeField is a String
    
    typeField is a DateTime
    

    or

    http://msdn.microsoft.com/en-us/library/58918ffs(v=vs.71).aspx

提交回复
热议问题