当前位置: 首页>>代码示例>>C#>>正文


C# ReadOnlySpan.SequenceEqual方法代码示例

本文整理汇总了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); });
            }
        }
开发者ID:AlexGhiondea,项目名称:corefxlab,代码行数:19,代码来源:UsageScenarioTests.cs

示例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);
        }
开发者ID:AlexGhiondea,项目名称:corefxlab,代码行数:23,代码来源:UsageScenarioTests.cs

示例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);
        }
开发者ID:AlexGhiondea,项目名称:corefxlab,代码行数:28,代码来源:UsageScenarioTests.cs

示例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));
            }
        }
开发者ID:TerabyteX,项目名称:corefxlab,代码行数:22,代码来源:UsageScenarioTests.cs


注:本文中的ReadOnlySpan.SequenceEqual方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。