3 ms·
Some are downright silly: > C#: You can't perform any operations, even simple arithmetic, with objects inside a generic method (e.g. T plus<T>(T t1, T t2) { re
by jakear 7y ago
Some are downright silly:
> C#: You can't perform any operations, even simple arithmetic, with objects inside a generic method (e.g. T plus<T>(T t1, T t2) { return t1+t2; }
Well... obviously.
- nmca 7y agoObviously? Surely that's just a type constraint.
- 1000units 7y agoYes, you have to specify the constraint for code that assumes the constraint to type-check.
- jakear 7y agoC# doesn't claim to have powerful type inference a la. Haskell, so there's no reason to expect it to extract type information from usage of parameters inside generic functions. If you need functionality inside the body, you gotta declare that functionality in the type constraints.