Skip to content
Discussion options

You must be logged in to vote

I think you're misinterpreting that documentation. It says that value types are boxed when the type does not implement/override a method from a base class. For example, calling ToString() on your MyArraySegment<T> would cause this kind of boxing. But ArraySegment<T> does implement IReadOnlyList<T>, so no boxing occurs; it doesn't matter that it's implemented explicitly. (In fact, the documentation calls out this boxing cannot happen with interfaces: "This last case can occur only when method was defined on Object, ValueType, or Enum and not overridden by thisType.")

To verify this, I've run your test code using Benchmark.Net:

[ShortRunJob]
[MemoryDiagnoser]
public class Benchmark
{
    Co…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@helviett
Comment options

Answer selected by helviett
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants