How to compare types

后端 未结 5 1622
半阙折子戏
半阙折子戏 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:41

    You can use for it the is operator. You can then check if object is specific type by writing:

    if (myObject is string)
    {
      DoSomething()
    }
    

提交回复
热议问题