You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Use `ArraySegment<T>` for efficient slicing of arrays
294
+
When slicing an array a new array is created. This is especially expensive when the array is large. `ArraySegment<T>` is a struct that holds a reference to the original array and the start and end index of the slice. This is much more efficient than creating a new one. Be aware that the `ArraySegment<T>` is a read-only view of the original array and any changes to the original array will be reflected in the `ArraySegment<T>`.
295
+
296
+
❌ **Bad** We create a new array when taking a slice of the original array, leading to extra memory allocations.
0 commit comments