diff options
-rw-r--r-- | src/mscorlib/shared/System/ReadOnlySpan.cs | 5 | ||||
-rw-r--r-- | src/mscorlib/shared/System/Span.cs | 5 |
2 files changed, 6 insertions, 4 deletions
diff --git a/src/mscorlib/shared/System/ReadOnlySpan.cs b/src/mscorlib/shared/System/ReadOnlySpan.cs index 28fb2e33e0..7a8243d669 100644 --- a/src/mscorlib/shared/System/ReadOnlySpan.cs +++ b/src/mscorlib/shared/System/ReadOnlySpan.cs @@ -261,12 +261,13 @@ namespace System /// <summary> /// Defines an implicit conversion of an array to a <see cref="ReadOnlySpan{T}"/> /// </summary> - public static implicit operator ReadOnlySpan<T>(T[] array) => new ReadOnlySpan<T>(array); + public static implicit operator ReadOnlySpan<T>(T[] array) => array != null ? new ReadOnlySpan<T>(array) : default; /// <summary> /// Defines an implicit conversion of a <see cref="ArraySegment{T}"/> to a <see cref="ReadOnlySpan{T}"/> /// </summary> - public static implicit operator ReadOnlySpan<T>(ArraySegment<T> arraySegment) => new ReadOnlySpan<T>(arraySegment.Array, arraySegment.Offset, arraySegment.Count); + public static implicit operator ReadOnlySpan<T>(ArraySegment<T> arraySegment) + => arraySegment.Array != null ? new ReadOnlySpan<T>(arraySegment.Array, arraySegment.Offset, arraySegment.Count) : default; /// <summary> /// Forms a slice out of the given read-only span, beginning at 'start'. diff --git a/src/mscorlib/shared/System/Span.cs b/src/mscorlib/shared/System/Span.cs index 90ef2fca06..ca146aef65 100644 --- a/src/mscorlib/shared/System/Span.cs +++ b/src/mscorlib/shared/System/Span.cs @@ -342,12 +342,13 @@ namespace System /// <summary> /// Defines an implicit conversion of an array to a <see cref="Span{T}"/> /// </summary> - public static implicit operator Span<T>(T[] array) => new Span<T>(array); + public static implicit operator Span<T>(T[] array) => array != null ? new Span<T>(array) : default; /// <summary> /// Defines an implicit conversion of a <see cref="ArraySegment{T}"/> to a <see cref="Span{T}"/> /// </summary> - public static implicit operator Span<T>(ArraySegment<T> arraySegment) => new Span<T>(arraySegment.Array, arraySegment.Offset, arraySegment.Count); + public static implicit operator Span<T>(ArraySegment<T> arraySegment) + => arraySegment.Array != null ? new Span<T>(arraySegment.Array, arraySegment.Offset, arraySegment.Count) : default; /// <summary> /// Defines an implicit conversion of a <see cref="Span{T}"/> to a <see cref="ReadOnlySpan{T}"/> |