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


C# ReadOnlySpan.DangerousGetPinnableReference方法代码示例

本文整理汇总了C#中ReadOnlySpan.DangerousGetPinnableReference方法的典型用法代码示例。如果您正苦于以下问题:C# ReadOnlySpan.DangerousGetPinnableReference方法的具体用法?C# ReadOnlySpan.DangerousGetPinnableReference怎么用?C# ReadOnlySpan.DangerousGetPinnableReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ReadOnlySpan的用法示例。


在下文中一共展示了ReadOnlySpan.DangerousGetPinnableReference方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SliceIntIntPastEnd

 public static void SliceIntIntPastEnd()
 {
     int[] a = { 90, 91, 92, 93, 94, 95, 96, 97, 98, 99 };
     ReadOnlySpan<int> span = new ReadOnlySpan<int>(a).Slice(a.Length, 0);
     Assert.Equal(0, span.Length);
     Assert.True(Unsafe.AreSame<int>(ref a[a.Length - 1], ref Unsafe.Subtract<int>(ref span.DangerousGetPinnableReference(), 1)));
 }
开发者ID:dotnet,项目名称:corefx,代码行数:7,代码来源:Slice.cs

示例2: SliceIntIntUpToEnd

 public static void SliceIntIntUpToEnd()
 {
     int[] a = { 90, 91, 92, 93, 94, 95, 96, 97, 98, 99 };
     ReadOnlySpan<int> span = new ReadOnlySpan<int>(a).Slice(4, 6);
     Assert.Equal(6, span.Length);
     Assert.True(Unsafe.AreSame<int>(ref a[4], ref span.DangerousGetPinnableReference()));
 }
开发者ID:dotnet,项目名称:corefx,代码行数:7,代码来源:Slice.cs

示例3: DangerousGetPinnableReferenceArray

 public static void DangerousGetPinnableReferenceArray()
 {
     int[] a = { 91, 92, 93, 94, 95 };
     ReadOnlySpan<int> span = new ReadOnlySpan<int>(a, 1, 3);
     ref int pinnableReference = ref span.DangerousGetPinnableReference();
     Assert.True(Unsafe.AreSame<int>(ref a[1], ref pinnableReference));
 }
开发者ID:dotnet,项目名称:corefx,代码行数:7,代码来源:DangerousGetPinnableReference.cs

示例4: PortableCastUIntToUShort

        public static void PortableCastUIntToUShort()
        {
            uint[] a = { 0x44332211, 0x88776655 };
            ReadOnlySpan<uint> span = new ReadOnlySpan<uint>(a);
            ReadOnlySpan<ushort> asUShort = span.NonPortableCast<uint, ushort>();

            Assert.True(Unsafe.AreSame<ushort>(ref Unsafe.As<uint, ushort>(ref span.DangerousGetPinnableReference()), ref asUShort.DangerousGetPinnableReference()));
            asUShort.Validate<ushort>(0x2211, 0x4433, 0x6655, 0x8877);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:9,代码来源:NonPortableCast.cs

示例5: CtorPointerNull

 public static void CtorPointerNull()
 {
     unsafe
     {
         ReadOnlySpan<int> span = new ReadOnlySpan<int>((void*)null, 0);
         span.Validate<int>();
         Assert.True(Unsafe.AreSame<int>(ref Unsafe.AsRef<int>((void*)null), ref span.DangerousGetPinnableReference()));
     }
 }
开发者ID:dotnet,项目名称:corefx,代码行数:9,代码来源:CtorPointerInt.cs

示例6: AsBytesUIntToByte

        public static void AsBytesUIntToByte()
        {
            uint[] a = { 0x44332211, 0x88776655 };
            ReadOnlySpan<uint> span = new ReadOnlySpan<uint>(a);
            ReadOnlySpan<byte> asBytes = span.AsBytes<uint>();

            Assert.True(Unsafe.AreSame<byte>(ref Unsafe.As<uint, byte>(ref span.DangerousGetPinnableReference()), ref asBytes.DangerousGetPinnableReference()));
            asBytes.Validate<byte>(0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:9,代码来源:AsBytes.cs

示例7: DangerousGetPinnableReferencePointer

 public static void DangerousGetPinnableReferencePointer()
 {
     unsafe
     {
         int i = 42;
         ReadOnlySpan<int> span = new ReadOnlySpan<int>(&i, 1);
         ref int pinnableReference = ref span.DangerousGetPinnableReference();
         Assert.True(Unsafe.AreSame<int>(ref i, ref pinnableReference));
     }
 }
开发者ID:dotnet,项目名称:corefx,代码行数:10,代码来源:DangerousGetPinnableReference.cs

示例8: DangerousGetPinnableReferenceArrayPastEnd

        public static void DangerousGetPinnableReferenceArrayPastEnd()
        {
            // The only real difference between DangerousGetPinnableReference() and "ref span[0]" is that
            // DangerousGetPinnableReference() of a zero-length won't throw an IndexOutOfRange.

            int[] a = { 91, 92, 93, 94, 95 };
            ReadOnlySpan<int> span = new ReadOnlySpan<int>(a, a.Length, 0);
            ref int pinnableReference = ref span.DangerousGetPinnableReference();
            ref int expected = ref Unsafe.Add<int>(ref a[a.Length - 1], 1);
            Assert.True(Unsafe.AreSame<int>(ref expected, ref pinnableReference));
        }
开发者ID:dotnet,项目名称:corefx,代码行数:11,代码来源:DangerousGetPinnableReference.cs

示例9: CtorPointerInt

 public static void CtorPointerInt()
 {
     unsafe
     {
         int[] a = { 90, 91, 92 };
         fixed (int *pa = a)
         {
             ReadOnlySpan<int> span = new ReadOnlySpan<int>(pa, 3);
             span.Validate<int>(90, 91, 92);
             Assert.True(Unsafe.AreSame<int>(ref Unsafe.AsRef<int>(pa), ref span.DangerousGetPinnableReference()));
         }
     }
 }
开发者ID:dotnet,项目名称:corefx,代码行数:13,代码来源:CtorPointerInt.cs


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