本文整理汇总了C#中ReadOnlySpan.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# ReadOnlySpan.ToArray方法的具体用法?C# ReadOnlySpan.ToArray怎么用?C# ReadOnlySpan.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReadOnlySpan
的用法示例。
在下文中一共展示了ReadOnlySpan.ToArray方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToArray1
public static void ToArray1()
{
int[] a = { 91, 92, 93 };
ReadOnlySpan<int> span = new ReadOnlySpan<int>(a);
int[] copy = span.ToArray();
Assert.Equal<int>(a, copy);
Assert.NotSame(a, copy);
}
示例2: CtorReadOnlySpanOverByteArrayValidCasesWithPropertiesAndBasicOperationsChecks
public void CtorReadOnlySpanOverByteArrayValidCasesWithPropertiesAndBasicOperationsChecks(byte[] array)
{
ReadOnlySpan<byte> span = new ReadOnlySpan<byte>(array);
Assert.Equal(array.Length, span.Length);
Assert.NotSame(array, span.ToArray());
for (int i = 0; i < span.Length; i++)
{
Assert.Equal(array[i], span.Slice(i).Read<byte>());
Assert.Equal(array[i], span.Slice(i).Read<MyByte>().Value);
array[i] = unchecked((byte)(array[i] + 1));
Assert.Equal(array[i], span.Slice(i).Read<byte>());
Assert.Equal(array[i], span.Slice(i).Read<MyByte>().Value);
}
}
示例3: CtorReadOnlySpanOverByteArrayValidCasesWithPropertiesAndBasicOperationsChecks
public void CtorReadOnlySpanOverByteArrayValidCasesWithPropertiesAndBasicOperationsChecks(byte[] array)
{
ReadOnlySpan<byte> span = new ReadOnlySpan<byte>(array);
Assert.Equal(array.Length, span.Length);
Assert.NotSame(array, span.ToArray());
Assert.True(span.Equals(array));
ReadOnlySpan<byte>.Enumerator it = span.GetEnumerator();
for (int i = 0; i < span.Length; i++)
{
Assert.True(it.MoveNext());
Assert.Equal(array[i], it.Current);
Assert.Equal(array[i], span.Slice(i).Read<byte>());
Assert.Equal(array[i], span.Slice(i).Read<MyByte>().Value);
array[i] = unchecked((byte)(array[i] + 1));
Assert.Equal(array[i], it.Current);
Assert.Equal(array[i], span.Slice(i).Read<byte>());
Assert.Equal(array[i], span.Slice(i).Read<MyByte>().Value);
}
Assert.False(it.MoveNext());
it.Reset();
for (int i = 0; i < span.Length; i++)
{
Assert.True(it.MoveNext());
Assert.Equal(array[i], it.Current);
}
Assert.False(it.MoveNext());
}