Custom class is not able to be used with generic type T
Hello everyone I am just programming and run into a problem.
I wrote a custom class:
However when I want to call it as a method parameter with generic type T it does not work:
private void DoSomeThing(ref ServiceResponse<T> serviceResponse){...}
it does not work.
Can someone please help me?
12 Replies
$details, "does not work" isn't specific
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, and what you expect the result to be. Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
provide an example of the code you're trying to write and share the errors you're getting
Are you literally typing T in the calling method as the type parameter?
I want to use the method to be able to run with any type for the rapper ServiceRespone. A Example for ServiceRespone would be ServiceRespone<List<GetProductDto>> or ServiceRespone<GetProduct>.
then the method has to be generic as well
like
DoSomeThing<T>(ref ServiceResponse<T> serviceResponse){...}
It is
So after the name of the method I have to wright <T>?
yes, that's how you define a generic method
I tested it your right
if you don't do that it's not generic and
T
has no meaning in that contextThanks a lot