Zum Inhalt springen

Boxing unboxing (ARCH602)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Key dotnet.performance.boxing-unboxing · Severity info · Category performance

Converting value types to object incurs heap allocation and copying overhead.

ArrayList list = new ArrayList();
list.Add(42); // boxing
int x = (int)list[0]; // unboxing
List<int> list = new List<int>();
list.Add(42);
int x = list[0];

Use generic collections and methods to eliminate boxing.