+ 1

[Answered] Generic SortedList quite literally assigned as <string, object> or SortedList non-generic?

[Answered] So, I have tested whether the type that you would get from an object at run-time differed between the two, and the answer is no. Now, the question I have is whether it matters which one of these you are using for performance, if you *literally* were to create the generic one with the types string, object. Answers would be greatly appreciated.

1st Apr 2021, 3:24 PM
️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️
️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️ - avatar
1 Respuesta
+ 2
In most cases generic types are just for linting perposes. That way your IDE knows what to expect. In C# in most cases it's just in time compiled so the generics are compiled into the intermediary language. This is helpful when you use your binary as a dynamic link library since you don't need the debug symbols to know what's going on. So to answer your question there isn't really a performance difference that I am aware of. At the end of the day the machine code works the same way. A reference in memory to where the array starts, the length of the array, and a reference to your object in memory. Whether that object is a string or an class there is no difference. There would be a difference if you use numbers instead because then there is no need for a reference to another memory location. You won't really know that because the compiler will decide how to optimize. I think a more interesting question is what happens when you mix reference types with non-refrence types.
2nd Apr 2021, 12:53 AM
Nommer101
Nommer101 - avatar