How can i make that
why is this not allowed? isnt the type restriciton enough?
i want to differentiate between structs and classes so i have a null check where needed and no unnecessary boxing and stuff
7 Replies
how can i automatically say "value types go there and everything else goes there"
having this and using
redirects me to the first implementation.. but how can the first implementation check the vector for null?
Why can't you just have one unconstrained implementation?
what does the unconstrained implementation with structs?
I don't understand the question
If you check whether T is null, that's just a no-op if T is a value type
what is a no op?
Iirc the JIT might even remove that code branch entirely when it emits implementations if that method for struct
A no-op is "no operation" - something which doesn't do anything
The jit has to compile a separate copy of your method for when T is a reference and a value type. When it compiles the value type version, it'll skip all code which doesn't make sense for value types, like null checks
So there's no harm in checking whether a value type is null.
ah goody
oke
then i will go with the second implementation as nullables are a problem type for me
thanks