Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there away in c# to omit the response type from a generic method?

In c# you can hide the type of the in parameter to a generic method.

Is it be possible to do the same when you have a in type and a generic method?

Code for visualization of what I am trying to achieve:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

public class A { ... }
public class B { ... }
private Task BaseMethod<T>(T request) {
    ...
}
private Task<R> BaseMethod<T, R>(T request) {
    ...
}
public Task foo(A request) => BaseMethod(request);
// The following line works
public Task<B> bar(A request) => BaseMethod<A, B>(request);
// But I wanted something like the next line
public Task<B> bar(A request) => BaseMethod(request);

Thanks for your time.

>Solution :

No, this is not currently a thing that is supported in the language.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading