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.
Incorrect
Section titled “Incorrect”ArrayList list = new ArrayList();list.Add(42); // boxingint x = (int)list[0]; // unboxingCorrect
Section titled “Correct”List<int> list = new List<int>();list.Add(42);int x = list[0];Use generic collections and methods to eliminate boxing.