本文整理汇总了C#中ReadOnlySpan.SequenceEqual方法的典型用法代码示例。如果您正苦于以下问题:C# ReadOnlySpan.SequenceEqual方法的具体用法?C# ReadOnlySpan.SequenceEqual怎么用?C# ReadOnlySpan.SequenceEqual使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReadOnlySpan
的用法示例。
在下文中一共展示了ReadOnlySpan.SequenceEqual方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ROSpanCopyToArrayTwoDifferentBuffersValidCases
public void ROSpanCopyToArrayTwoDifferentBuffersValidCases(byte[] expected, byte[] a, int aidx, int acount, byte[] b)
{
if (expected != null)
{
ReadOnlySpan<byte> spanA = new ReadOnlySpan<byte>(a, aidx, acount);
spanA.CopyTo(b);
Assert.Equal(expected, b);
ReadOnlySpan<byte> spanExpected = new ReadOnlySpan<byte>(expected);
ReadOnlySpan<byte> spanBAll = new ReadOnlySpan<byte>(b);
Assert.True(spanExpected.SequenceEqual(spanBAll));
}
else
{
ReadOnlySpan<byte> spanA = new ReadOnlySpan<byte>(a, aidx, acount);
Assert.ThrowsAny<Exception>(() => { spanA.CopyTo(b); });
}
}
示例2: ReadOnlySpanOfByteCopyToAnotherSpanOfByteTwoDifferentBuffersValidCases
public void ReadOnlySpanOfByteCopyToAnotherSpanOfByteTwoDifferentBuffersValidCases(byte[] expected, byte[] a, int aidx, int acount, byte[] b, int bidx, int bcount)
{
if (expected != null)
{
ReadOnlySpan<byte> spanA = new ReadOnlySpan<byte>(a, aidx, acount);
Span<byte> spanB = new Span<byte>(b, bidx, bcount);
spanA.CopyTo(spanB);
Assert.Equal(expected, b);
ReadOnlySpan<byte> spanExpected = new ReadOnlySpan<byte>(expected);
ReadOnlySpan<byte> spanBAll = new ReadOnlySpan<byte>(b);
Assert.True(spanExpected.SequenceEqual(spanBAll));
}
else
{
ReadOnlySpan<byte> spanA = new ReadOnlySpan<byte>(a, aidx, acount);
Span<byte> spanB = new Span<byte>(b, bidx, bcount);
Assert.ThrowsAny<Exception>(() => { spanA.CopyTo(spanB); });
}
ReadOnlySpanOfByteCopyToAnotherSpanOfByteTwoDifferentBuffersValidCasesNative(expected, a, aidx, acount, b, bidx, bcount);
}
示例3: ReadOnlySpanOfByteCopyToAnotherSpanOfByteTwoDifferentBuffersValidCasesNative
public unsafe void ReadOnlySpanOfByteCopyToAnotherSpanOfByteTwoDifferentBuffersValidCasesNative(byte[] expected, byte[] a, int aidx, int acount, byte[] b, int bidx, int bcount)
{
IntPtr pa = Marshal.AllocHGlobal(a.Length);
Span<byte> na = new Span<byte>(pa.ToPointer(), a.Length);
a.CopyTo(na);
IntPtr pb = Marshal.AllocHGlobal(b.Length);
Span<byte> nb = new Span<byte>(pb.ToPointer(), b.Length);
b.CopyTo(nb);
ReadOnlySpan<byte> spanA = na.Slice(aidx, acount);
Span<byte> spanB = nb.Slice(bidx, bcount);
if (expected != null) {
spanA.CopyTo(spanB);
Assert.Equal(expected, b);
ReadOnlySpan<byte> spanExpected = new ReadOnlySpan<byte>(expected);
ReadOnlySpan<byte> spanBAll = new ReadOnlySpan<byte>(b);
Assert.True(spanExpected.SequenceEqual(spanBAll));
}
else {
Assert.ThrowsAny<Exception>(() => { spanA.CopyTo(spanB); });
}
Marshal.FreeHGlobal(pa);
Marshal.FreeHGlobal(pb);
}
示例4: ReadOnlySpanOfByteCopyToAnotherSpanOfByteTwoDifferentBuffersValidCases
[CLSCompliant(false)] // TODO: find out why the assembly-level CLSCompliant=false doesn't work
public void ReadOnlySpanOfByteCopyToAnotherSpanOfByteTwoDifferentBuffersValidCases(byte[] expected, byte[] a, int aidx, int acount, byte[] b, int bidx, int bcount)
{
if (expected != null)
{
ReadOnlySpan<byte> spanA = new ReadOnlySpan<byte>(a, aidx, acount);
Span<byte> spanB = new Span<byte>(b, bidx, bcount);
Assert.True(spanA.TryCopyTo(spanB));
Assert.Equal(expected, b);
ReadOnlySpan<byte> spanExpected = new ReadOnlySpan<byte>(expected);
ReadOnlySpan<byte> spanBAll = new ReadOnlySpan<byte>(b);
Assert.True(spanExpected.SequenceEqual(spanBAll));
}
else
{
ReadOnlySpan<byte> spanA = new ReadOnlySpan<byte>(a, aidx, acount);
Span<byte> spanB = new Span<byte>(b, bidx, bcount);
Assert.False(spanA.TryCopyTo(spanB));
}
}