Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit e8aef19

Browse files
Allow implicit conversion of null arrays to empty Memory instances
1 parent f1c7328 commit e8aef19

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/mscorlib/shared/System/Memory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private Memory(object obj, int index, int length)
106106
/// <summary>
107107
/// Defines an implicit conversion of an array to a <see cref="Memory{T}"/>
108108
/// </summary>
109-
public static implicit operator Memory<T>(T[] array) => new Memory<T>(array);
109+
public static implicit operator Memory<T>(T[] array) => (array != null) ? new Memory<T>(array) : default;
110110

111111
/// <summary>
112112
/// Defines an implicit conversion of a <see cref="ArraySegment{T}"/> to a <see cref="Memory{T}"/>

src/mscorlib/shared/System/ReadOnlyMemory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ internal ReadOnlyMemory(object obj, int start, int length)
9797
/// <summary>
9898
/// Defines an implicit conversion of an array to a <see cref="ReadOnlyMemory{T}"/>
9999
/// </summary>
100-
public static implicit operator ReadOnlyMemory<T>(T[] array) => new ReadOnlyMemory<T>(array);
100+
public static implicit operator ReadOnlyMemory<T>(T[] array) => (array != null) ? new ReadOnlyMemory<T>(array) : default;
101101

102102
/// <summary>
103103
/// Defines an implicit conversion of a <see cref="ArraySegment{T}"/> to a <see cref="ReadOnlyMemory{T}"/>

0 commit comments

Comments
 (0)