4 ms·
I think this is only true in C# for value types - I think the same generated code is used for all reference types, so eg. `List<object>` uses the same code as `
by Diggsey 4y ago
I think this is only true in C# for value types - I think the same generated code is used for all reference types, so eg. `List<object>` uses the same code as `List<string>` but different from `List<int>`.
- merb 4y agowell yeah. it's explained here: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/generics-in-the-run-time https://docs.microsoft.com/en-us/dotnet/csharp/programming-g... btw. it's not called "runtime evaluation" and more or less a kind of runtime substitution. (because nothing gets evaluated it gets substituted) and btw. c++ allows references types to have specializations, this is not possible in c#
- jhgb 4y agoThis is to be expected with what are essentially pointers to heap objects. The actual code being executed only manipulates machine-word-sized values with the same semantics, so it makes little sense to have copies of the same code.
- astrange 4y agoIt could be useful to duplicate it for devirtualization, and that's more likely with a JIT than compilation since it doesn't cost code size on disk.
- jhgb 4y agoWell, yes. But you can't devirtualize until you know the types as well as possible, which is after "de-generifying", so as to speak (I don't really know what terminology .NET uses for this).