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