+ 4
Can generic types provide methods?
I may be too quick to ask as I have only started the section on generics. What I wonder is if generic types can provide methods đ€ I do not have a concrete idea, yet. But let's say a method only know what to do but not how. But the type knows how: void DoSomething<T, A>(T knows, A withWhat) { // do what DoSomething can do knows.howToDoIt(withWhat); // continue ... } The idea is to be able to change some details of the method based on the type đ Thank you đ€đ
2 Answers
+ 1
Sounds good ....
However unlike C++ you cannot use Specialization in C#.
Itâs down to generics, simply put a generic version of class or method for <T> must be the same for all instances.
You can work around by embedding checks within the method but this kind of goes against the grain of generics.
0
Thank you đ€đ Yes, interesting đ€đ