Let method take any data type in c#

后端 未结 6 1425
栀梦
栀梦 2020-12-08 04:29

I have a lot of unit tests that pretty much tests the same behavior. However, data type changes.

I am trying to create a generic method that can take any data type.

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-08 05:16

    try to use dynamic keyword, this will work provided that all of your different types have the same methods that are used by your unit tests, otherwise you will get a run-time exception

提交回复
热议问题