Allow implicit conversion of null arrays to empty Memory instances
authorLevi Broderick <levib@microsoft.com>
Fri, 19 Jan 2018 19:50:02 +0000 (11:50 -0800)
committerLevi Broderick <levib@microsoft.com>
Fri, 19 Jan 2018 19:58:07 +0000 (11:58 -0800)
src/mscorlib/shared/System/Memory.cs
src/mscorlib/shared/System/ReadOnlyMemory.cs

index 9cb6e38..c828e5d 100644 (file)
@@ -106,7 +106,7 @@ namespace System
         /// <summary>
         /// Defines an implicit conversion of an array to a <see cref="Memory{T}"/>
         /// </summary>
-        public static implicit operator Memory<T>(T[] array) => new Memory<T>(array);
+        public static implicit operator Memory<T>(T[] array) => (array != null) ? new Memory<T>(array) : default;
 
         /// <summary>
         /// Defines an implicit conversion of a <see cref="ArraySegment{T}"/> to a <see cref="Memory{T}"/>
index d0f8a47..ba2f4dd 100644 (file)
@@ -97,7 +97,7 @@ namespace System
         /// <summary>
         /// Defines an implicit conversion of an array to a <see cref="ReadOnlyMemory{T}"/>
         /// </summary>
-        public static implicit operator ReadOnlyMemory<T>(T[] array) => new ReadOnlyMemory<T>(array);
+        public static implicit operator ReadOnlyMemory<T>(T[] array) => (array != null) ? new ReadOnlyMemory<T>(array) : default;
 
         /// <summary>
         /// Defines an implicit conversion of a <see cref="ArraySegment{T}"/> to a <see cref="ReadOnlyMemory{T}"/>