Generics and type inference
Why can't the compiler infer my type of TSource? If I call that mehod I always have to specify it like this It should be possible to call it just like this I am just starting with .NET
8 Replies
There is no partial inference, you either have to specify all or no generic parameters.
And yes this is annoying
Oh that sucks I love using generics to simplify code, anyway thank you for your quick help!
np language do you come from btw?
@thinker227 I did most of my work with python/c++ and recently very much with Haskell (loving it) - whats your main language?
C# but also doing a bit of Haskell occasionally.
Was just wondering what language you were using if you were expecting this kind of partial generic inference.
C#'s type system is unfortunately nowhere as sophisticated as Haskell's or what you can do with C++ templates.
Yeah its from my experiences with C++ templates and especially Haskell I just like working with strong typesystems. btw thats why Rust is simply awesome imho
Fair point
Compared to a lot of other ones, C#'s type system is quite tame.
True in comparsion, but its fine C# has some nice features too like record types which I've just learned about. I'm starting to try build up a github profile with some showcases thats why I try to learn different techs (webAPI in the C# case)