Answer the question
In order to leave comments, you need to log in
C#. Is it possible to create a method in which the return type will be determined in the method itself?
Is it possible to create a method in which the return type will be determined in the method itself, or dotnet strict typing will not allow this?
The returned type will depend on what comes in the response from the API (several type options that will be explicitly specified in the method itself).
Answer the question
In order to leave comments, you need to log in
The returned type will depend on what comes in the response from the API (several type options that will be explicitly specified in the method itself).
You return the most basic type object
, but this is shit code. The API usually returns a known data structure.
No, C# does not support type unioning. You can generalize, use a template or container, inherit, use an interface. But the most correct solution would be to rewrite the api method so that it returns a previously known type (this is the point of api).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question