3 ms·
That's why be put a struct constraint in. We'll quietly ignore the fact that non-primitive structs are as rare as hens teeth in most C# code-bases...
by moomin 9y ago
That's why be put a struct constraint in. We'll quietly ignore the fact that non-primitive structs are as rare as hens teeth in most C# code-bases...
- lmm 9y agoSo you might be able to use some kind of linter to enforce that you only ever call default(MA) where MA: struct, but even then, is it safe to assume that default(x) instantiates x in a valid state for all structs? Wouldn't that then mean that e.g. you couldn't ever use a struct containing a reference type anywhere in your codebase, since if you do then default(x) initialises that struct to contain a null reference, right?
- louthy 9y agoThe structs used as ‘class instaces’ aren’t statefull. The compiler will actually optimise out the ‘default’ also, so it’s as efficient as calling a static method. Anyway, nobody is arguing that this is some perfect system, merely that return type polymorphism can be achieved _relatively_ painlessly in a language other than Haskell.