Let method take any data type in c#

后端 未结 6 1414
栀梦
栀梦 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:02

    You can take in object as a parameter type. Even better, perhaps, would be to use generics:

    void MyMethod(T parm) { ... }
    

    This way the parameter is actually of the type the user passed in -- it isn't boxed like with object and value types.

提交回复
热议问题