-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Unsafe.xml
3035 lines (2840 loc) · 178 KB
/
Unsafe.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<Type Name="Unsafe" FullName="System.Runtime.CompilerServices.Unsafe">
<TypeSignature Language="C#" Value="public static class Unsafe" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi abstract sealed beforefieldinit Unsafe extends System.Object" />
<TypeSignature Language="DocId" Value="T:System.Runtime.CompilerServices.Unsafe" />
<TypeSignature Language="VB.NET" Value="Public Class Unsafe" />
<TypeSignature Language="F#" Value="type Unsafe = class" />
<TypeSignature Language="C++ CLI" Value="public ref class Unsafe abstract sealed" />
<AssemblyInfo>
<AssemblyName>System.Runtime.CompilerServices.Unsafe</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.2.0</AssemblyVersion>
<AssemblyVersion>4.0.4.0</AssemblyVersion>
<AssemblyVersion>4.0.4.1</AssemblyVersion>
<AssemblyVersion>4.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.6.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<TypeForwardingChain>
<TypeForwarding From="System.Runtime.CompilerServices.Unsafe" FromVersion="7.0.0.0" To="System.Runtime" ToVersion="7.0.0.0" FrameworkAlternate="net-7.0" />
<TypeForwarding From="System.Runtime.CompilerServices.Unsafe" FromVersion="8.0.0.0" To="System.Runtime" ToVersion="8.0.0.0" FrameworkAlternate="net-8.0" />
<TypeForwarding From="System.Runtime.CompilerServices.Unsafe" FromVersion="9.0.0.0" To="System.Runtime" ToVersion="9.0.0.0" FrameworkAlternate="net-9.0" />
</TypeForwardingChain>
<Base>
<BaseTypeName>System.Object</BaseTypeName>
</Base>
<Interfaces />
<Attributes>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(0)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(0)>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.NullableContext(1)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.NullableContext(1)>]</AttributeName>
</Attribute>
</Attributes>
<Docs>
<summary>Contains generic, low-level functionality for manipulating managed and unmanaged pointers.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
> [!WARNING]
> This type is intended for advanced pointer manipulation scenarios. Callers are assumed to be familiar with [ECMA-335](https://www.ecma-international.org/publications-and-standards/standards/ecma-335/), Sec. II.14.4 and III.1.1.5, and with the [ECMA-335 CLI Specification Addendum](https://github.com/dotnet/runtime/blob/main/docs/design/specs/Ecma-335-Augments.md).
>
> Most APIs on this type do not perform any argument checking or validation. Incorrect use of these APIs could corrupt process memory or destabilize the .NET runtime.
This type is typically used by low-level library authors who want to write high-performance code and are willing to suppress .NET's typical type safety checks to meet their performance goals.
Consider the following example, which reverses the elements within a `Span<T>`.
> [!NOTE]
> These examples exist simply for demonstration purposes. In real-world applications, developers should instead use helper functions like <xref:System.MemoryExtensions.Reverse%2A>, which are better optimized than even these examples.
```cs
// A safe, verifiable way to reverse a Span<T>.
static void Reverse<T>(Span<T> span)
{
while (span.Length > 1)
{
T firstElement = span[0];
T lastElement = span[^1];
span[0] = lastElement;
span[^1] = firstElement;
span = span[1..^1];
}
}
```
This method is fully type-safe and the .NET runtime may insert bounds checks to help enforce safety. However, low-level library authors may want to suppress .NET's normal safety checks in order to improve the performance of their own code. Such developers would typically rely on static analysis tools or their own code reviews to help enforce correctness. The `Unsafe` APIs allow a developer to rewrite this code using unverifiable constructs, as the following example shows.
```cs
// A correct but unverifiable way to reverse a Span<T>.
static void Reverse<T>(Span<T> span)
{
if (span.Length > 1)
{
ref T refLeft = ref MemoryMarshal.GetReference(span);
ref T refRight = ref Unsafe.Add(ref refLeft, span.Length - 1);
do
{
T leftElement = refLeft;
T rightElement = refRight;
refLeft = rightElement;
refRight = leftElement;
refLeft = ref Unsafe.Add(ref refLeft, 1);
refRight = ref Unsafe.Subtract(ref refRight, 1);
} while (Unsafe.IsAddressLessThan(ref refLeft, ref refRight));
}
}
```
Since the `Unsafe` APIs suppress typical type-safety validation, it is up to callers to ensure that the code they're writing is legal. Misuse of these APIs could cause access violations, create GC holes, produce incorrect codegen, or otherwise induce undefined and destabilizing behaviors within the .NET runtime.
]]></format>
</remarks>
</Docs>
<Members>
<Member MemberName="Add<T>">
<MemberSignature Language="C#" Value="public static void* Add<T> (void* source, int elementOffset);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig void* Add<T>(void* source, int32 elementOffset) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Runtime.CompilerServices.Unsafe.Add``1(System.Void*,System.Int32)" />
<MemberSignature Language="F#" Value="static member Add : nativeptr<unit> * int -> nativeptr<unit>" Usage="System.Runtime.CompilerServices.Unsafe.Add (source, elementOffset)" />
<MemberSignature Language="C++ CLI" Value="public:
generic <typename T>
 static void* Add(void* source, int elementOffset);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime.CompilerServices.Unsafe</AssemblyName>
<AssemblyVersion>4.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.6.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="net-7.0;net-8.0;net-9.0">
<AttributeName Language="C#">[System.CLSCompliant(false)]</AttributeName>
<AttributeName Language="F#">[<System.CLSCompliant(false)>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.NullableContext(0)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.NullableContext(0)>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Void*</ReturnType>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="T">
<Attributes>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(2)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(2)>]</AttributeName>
</Attribute>
</Attributes>
</TypeParameter>
</TypeParameters>
<Parameters>
<Parameter Name="source" Type="System.Void*" Index="0" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-3.0;netcore-3.1;netstandard-2.0" />
<Parameter Name="elementOffset" Type="System.Int32" Index="1" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-3.0;netcore-3.1;netstandard-2.0" />
</Parameters>
<Docs>
<typeparam name="T">The type whose size will be used as a scale factor for <paramref name="elementOffset" />.</typeparam>
<param name="source">The unmanaged pointer to add the offset to.</param>
<param name="elementOffset">The offset to add.</param>
<summary>Adds an element offset to the given unmanaged pointer.</summary>
<returns>A new unmanaged pointer that reflects the addition of the specified offset to the source pointer.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The `elementOffset` parameter is the number of `T`-sized elements (not bytes) to add to the `source` pointer. For example, given a source pointer _ptr_, the call `Unsafe.Add<int>(ptr, 20)` will return a new pointer whose address points 80 bytes (= 20 elements \* 4 bytes per element) beyond _ptr_.
If `elementOffset` is a calculated value rather than a hardcoded literal, callers should consider the possibility of integer overflow. For example, in the call `Unsafe.Add<int>(ptr, a * b)`, the caller must ensure the intermediate value `a * b` does not overflow the bounds of `Int32`.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="Add<T>">
<MemberSignature Language="C#" Value="public static ref T Add<T> (ref T source, int elementOffset);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig !!T Add<T>(!!T& source, int32 elementOffset) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Runtime.CompilerServices.Unsafe.Add``1(``0@,System.Int32)" />
<MemberSignature Language="VB.NET" Value="Public Shared Function Add(Of T) (ByRef source As T, elementOffset As Integer) As T" />
<MemberSignature Language="F#" Value="static member Add : 'T * int -> 'T" Usage="System.Runtime.CompilerServices.Unsafe.Add (source, elementOffset)" />
<MemberSignature Language="C++ CLI" Value="public:
generic <typename T>
 static T % Add(T % source, int elementOffset);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime.CompilerServices.Unsafe</AssemblyName>
<AssemblyVersion>4.0.2.0</AssemblyVersion>
<AssemblyVersion>4.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.6.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue RefType="Ref">
<ReturnType>T</ReturnType>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="T">
<Attributes>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(2)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(2)>]</AttributeName>
</Attribute>
</Attributes>
</TypeParameter>
</TypeParameters>
<Parameters>
<Parameter Name="source" Type="T" RefType="ref" Index="0" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-1.1;netcore-3.0;netcore-3.1;netstandard-2.0" />
<Parameter Name="elementOffset" Type="System.Int32" Index="1" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-1.1;netcore-3.0;netcore-3.1;netstandard-2.0" />
</Parameters>
<Docs>
<typeparam name="T">The elemental type of the managed pointer.</typeparam>
<param name="source">The managed pointer to add the offset to.</param>
<param name="elementOffset">The offset to add.</param>
<summary>Adds an offset to the given managed pointer.</summary>
<returns>A new managed pointer that reflects the addition of the specified offset to the source pointer.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The `elementOffset` parameter is the number of `T`-sized elements (not bytes) to add to the `source` pointer. For example, given a source pointer _ptr_ of type `ref int`, the call `Unsafe.Add<int>(ref ptr, 20)` will return a new pointer whose address points 80 bytes (= 20 elements \* 4 bytes per element) beyond _ptr_.
If `elementOffset` is a calculated value rather than a hardcoded literal, callers should consider the possibility of integer overflow. For example, in the call `Unsafe.Add<int>(ref ptr, a * b)`, the caller must ensure the intermediate value `a * b` does not overflow the bounds of `Int32`.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="Add<T>">
<MemberSignature Language="C#" Value="public static ref T Add<T> (ref T source, IntPtr elementOffset);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig !!T Add<T>(!!T& source, native int elementOffset) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Runtime.CompilerServices.Unsafe.Add``1(``0@,System.IntPtr)" />
<MemberSignature Language="VB.NET" Value="Public Shared Function Add(Of T) (ByRef source As T, elementOffset As IntPtr) As T" />
<MemberSignature Language="F#" Value="static member Add : 'T * nativeint -> 'T" Usage="System.Runtime.CompilerServices.Unsafe.Add (source, elementOffset)" />
<MemberSignature Language="C++ CLI" Value="public:
generic <typename T>
 static T % Add(T % source, IntPtr elementOffset);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime.CompilerServices.Unsafe</AssemblyName>
<AssemblyVersion>4.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.6.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue RefType="Ref">
<ReturnType>T</ReturnType>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="T">
<Attributes>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(2)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(2)>]</AttributeName>
</Attribute>
</Attributes>
</TypeParameter>
</TypeParameters>
<Parameters>
<Parameter Name="source" Type="T" RefType="ref" Index="0" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-3.0;netcore-3.1;netstandard-2.0" />
<Parameter Name="elementOffset" Type="System.IntPtr" Index="1" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-3.0;netcore-3.1;netstandard-2.0" />
</Parameters>
<Docs>
<typeparam name="T">The elemental type of the managed pointer.</typeparam>
<param name="source">The managed pointer to add the offset to.</param>
<param name="elementOffset">The offset to add.</param>
<summary>Adds an element offset to the given managed pointer.</summary>
<returns>A new managed pointer that reflects the addition of the specified offset to the source pointer.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The `elementOffset` parameter is the number of `T`-sized elements (not bytes) to add to the `source` pointer. For example, given a source pointer _ptr_ of type `ref int`, the call `Unsafe.Add<int>(ref ptr, (nint)20)` will return a new pointer whose address points 80 bytes (= 20 elements \* 4 bytes per element) beyond _ptr_.
If `elementOffset` is a calculated value rather than a hardcoded literal, callers should consider the possibility of integer overflow. For example, in the call `Unsafe.Add<int>(ref ptr, a * b)`, the caller must ensure the intermediate value `a * b` does not overflow the bounds of `IntPtr`.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="Add<T>">
<MemberSignature Language="C#" Value="public static ref T Add<T> (ref T source, nuint elementOffset);" FrameworkAlternate="net-6.0;netstandard-2.0" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig !!T Add<T>(!!T& source, native unsigned int elementOffset) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Runtime.CompilerServices.Unsafe.Add``1(``0@,System.UIntPtr)" />
<MemberSignature Language="VB.NET" Value="Public Shared Function Add(Of T) (ByRef source As T, elementOffset As UIntPtr) As T" />
<MemberSignature Language="F#" Value="static member Add : 'T * unativeint -> 'T" Usage="System.Runtime.CompilerServices.Unsafe.Add (source, elementOffset)" />
<MemberSignature Language="C++ CLI" Value="public:
generic <typename T>
 static T % Add(T % source, UIntPtr elementOffset);" />
<MemberSignature Language="C#" Value="public static ref T Add<T> (ref T source, UIntPtr elementOffset);" FrameworkAlternate="net-7.0;net-8.0;net-9.0" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime.CompilerServices.Unsafe</AssemblyName>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="net-7.0;net-8.0;net-9.0">
<AttributeName Language="C#">[System.CLSCompliant(false)]</AttributeName>
<AttributeName Language="F#">[<System.CLSCompliant(false)>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue RefType="Ref">
<ReturnType>T</ReturnType>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="T">
<Attributes>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(2)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(2)>]</AttributeName>
</Attribute>
</Attributes>
</TypeParameter>
</TypeParameters>
<Parameters>
<Parameter Name="source" Type="T" RefType="ref" Index="0" FrameworkAlternate="net-6.0;net-7.0;net-8.0;net-9.0;netstandard-2.0" />
<Parameter Name="elementOffset" Type="System.UIntPtr" Index="1" FrameworkAlternate="net-6.0;net-7.0;net-8.0;net-9.0;netstandard-2.0">
<Attributes>
<Attribute FrameworkAlternate="net-6.0;netstandard-2.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.NativeInteger]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.NativeInteger>]</AttributeName>
</Attribute>
</Attributes>
</Parameter>
</Parameters>
<Docs>
<typeparam name="T">The elemental type of the managed pointer.</typeparam>
<param name="source">The managed pointer to add the offset to.</param>
<param name="elementOffset">The offset to add.</param>
<summary>Adds an element offset to the given managed pointer.</summary>
<returns>A new managed pointer that reflects the addition of the specified offset to the source pointer.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The `elementOffset` parameter is the number of `T`-sized elements (not bytes) to add to the `source` pointer. For example, given a source pointer _ptr_ of type `ref int`, the call `Unsafe.Add<int>(ref ptr, (nuint)20)` will return a new pointer whose address points 80 bytes (= 20 elements \* 4 bytes per element) beyond _ptr_.
If `elementOffset` is a calculated value rather than a hardcoded literal, callers should consider the possibility of integer overflow. For example, in the call `Unsafe.Add<int>(ref ptr, a * b)`, the caller must ensure the intermediate value `a * b` does not overflow the bounds of `UIntPtr`.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="AddByteOffset<T>">
<MemberSignature Language="C#" Value="public static ref T AddByteOffset<T> (ref T source, IntPtr byteOffset);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig !!T AddByteOffset<T>(!!T& source, native int byteOffset) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Runtime.CompilerServices.Unsafe.AddByteOffset``1(``0@,System.IntPtr)" />
<MemberSignature Language="VB.NET" Value="Public Shared Function AddByteOffset(Of T) (ByRef source As T, byteOffset As IntPtr) As T" />
<MemberSignature Language="F#" Value="static member AddByteOffset : 'T * nativeint -> 'T" Usage="System.Runtime.CompilerServices.Unsafe.AddByteOffset (source, byteOffset)" />
<MemberSignature Language="C++ CLI" Value="public:
generic <typename T>
 static T % AddByteOffset(T % source, IntPtr byteOffset);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime.CompilerServices.Unsafe</AssemblyName>
<AssemblyVersion>4.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.6.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue RefType="Ref">
<ReturnType>T</ReturnType>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="T">
<Attributes>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(2)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(2)>]</AttributeName>
</Attribute>
</Attributes>
</TypeParameter>
</TypeParameters>
<Parameters>
<Parameter Name="source" Type="T" RefType="ref" Index="0" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-3.0;netcore-3.1;netstandard-2.0" />
<Parameter Name="byteOffset" Type="System.IntPtr" Index="1" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-3.0;netcore-3.1;netstandard-2.0" />
</Parameters>
<Docs>
<typeparam name="T">The elemental type of the managed pointer.</typeparam>
<param name="source">The managed pointer to add the offset to.</param>
<param name="byteOffset">The offset to add.</param>
<summary>Adds a byte offset to the given managed pointer.</summary>
<returns>A new managed pointer that reflects the addition of the specified byte offset to the source pointer.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The `byteOffset` parameter is the number of bytes to add to the `source` pointer. For example, given a source pointer _ptr_ of type `ref int`, the call `Unsafe.AddByteOffset<int>(ref ptr, 20)` will return a new pointer whose address points 20 bytes beyond _ptr_.
If `byteOffset` is a calculated value rather than a hardcoded literal, callers should consider the possibility of integer overflow. For example, in the call `Unsafe.AddByteOffset<int>(ref ptr, a * b)`, the caller must ensure the intermediate value `a * b` does not overflow the bounds of `IntPtr`.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="AddByteOffset<T>">
<MemberSignature Language="C#" Value="public static ref T AddByteOffset<T> (ref T source, nuint byteOffset);" FrameworkAlternate="net-6.0;netstandard-2.0" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig !!T AddByteOffset<T>(!!T& source, native unsigned int byteOffset) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Runtime.CompilerServices.Unsafe.AddByteOffset``1(``0@,System.UIntPtr)" />
<MemberSignature Language="VB.NET" Value="Public Shared Function AddByteOffset(Of T) (ByRef source As T, byteOffset As UIntPtr) As T" />
<MemberSignature Language="F#" Value="static member AddByteOffset : 'T * unativeint -> 'T" Usage="System.Runtime.CompilerServices.Unsafe.AddByteOffset (source, byteOffset)" />
<MemberSignature Language="C++ CLI" Value="public:
generic <typename T>
 static T % AddByteOffset(T % source, UIntPtr byteOffset);" />
<MemberSignature Language="C#" Value="public static ref T AddByteOffset<T> (ref T source, UIntPtr byteOffset);" FrameworkAlternate="net-7.0;net-8.0;net-9.0" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime.CompilerServices.Unsafe</AssemblyName>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="net-7.0;net-8.0;net-9.0">
<AttributeName Language="C#">[System.CLSCompliant(false)]</AttributeName>
<AttributeName Language="F#">[<System.CLSCompliant(false)>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue RefType="Ref">
<ReturnType>T</ReturnType>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="T">
<Attributes>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(2)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(2)>]</AttributeName>
</Attribute>
</Attributes>
</TypeParameter>
</TypeParameters>
<Parameters>
<Parameter Name="source" Type="T" RefType="ref" Index="0" FrameworkAlternate="net-6.0;net-7.0;net-8.0;net-9.0;netstandard-2.0" />
<Parameter Name="byteOffset" Type="System.UIntPtr" Index="1" FrameworkAlternate="net-6.0;net-7.0;net-8.0;net-9.0;netstandard-2.0">
<Attributes>
<Attribute FrameworkAlternate="net-6.0;netstandard-2.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.NativeInteger]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.NativeInteger>]</AttributeName>
</Attribute>
</Attributes>
</Parameter>
</Parameters>
<Docs>
<typeparam name="T">The elemental type of the managed pointer.</typeparam>
<param name="source">The managed pointer to add the offset to.</param>
<param name="byteOffset">The offset to add.</param>
<summary>Adds a byte offset to the given managed pointer.</summary>
<returns>A new managed pointer that reflects the addition of the specified byte offset to the source pointer.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The `byteOffset` parameter is the number of bytes to add to the `source` pointer. For example, given a source pointer _ptr_ of type `ref int`, the call `Unsafe.AddByteOffset<int>(ref ptr, (nuint)20)` will return a new pointer whose address points 20 bytes beyond _ptr_.
If `byteOffset` is a calculated value rather than a hardcoded literal, callers should consider the possibility of integer overflow. For example, in the call `Unsafe.AddByteOffset<int>(ref ptr, a * b)`, the caller must ensure the intermediate value `a * b` does not overflow the bounds of `UIntPtr`.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="AreSame<T>">
<MemberSignature Language="C#" Value="public static bool AreSame<T> (ref T left, ref T right);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig bool AreSame<T>(!!T& left, !!T& right) cil managed" FrameworkAlternate="net-5.0;net-6.0;net-7.0;netcore-1.1;netcore-3.0;netcore-3.1;netstandard-2.0" />
<MemberSignature Language="DocId" Value="M:System.Runtime.CompilerServices.Unsafe.AreSame``1(``0@,``0@)" />
<MemberSignature Language="VB.NET" Value="Public Shared Function AreSame(Of T) (ByRef left As T, ByRef right As T) As Boolean" />
<MemberSignature Language="F#" Value="static member AreSame : 'T * 'T -> bool" Usage="System.Runtime.CompilerServices.Unsafe.AreSame (left, right)" />
<MemberSignature Language="C++ CLI" Value="public:
generic <typename T>
 static bool AreSame(T % left, T % right);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig bool AreSame<T>([in]!!T& left, [in]!!T& right) cil managed" FrameworkAlternate="net-8.0;net-9.0" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime.CompilerServices.Unsafe</AssemblyName>
<AssemblyVersion>4.0.2.0</AssemblyVersion>
<AssemblyVersion>4.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.6.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="T">
<Attributes>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(2)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(2)>]</AttributeName>
</Attribute>
</Attributes>
</TypeParameter>
</TypeParameters>
<Parameters>
<Parameter Name="left" Type="T" RefType="ref" Index="0" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-1.1;netcore-3.0;netcore-3.1;netstandard-2.0">
<Attributes>
<Attribute FrameworkAlternate="net-5.0;net-7.0;net-8.0;net-9.0">
<AttributeName Language="C#">[System.Diagnostics.CodeAnalysis.AllowNull]</AttributeName>
<AttributeName Language="F#">[<System.Diagnostics.CodeAnalysis.AllowNull>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.RequiresLocation]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.RequiresLocation>]</AttributeName>
</Attribute>
</Attributes>
</Parameter>
<Parameter Name="right" Type="T" RefType="ref" Index="1" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-1.1;netcore-3.0;netcore-3.1;netstandard-2.0">
<Attributes>
<Attribute FrameworkAlternate="net-5.0;net-7.0;net-8.0;net-9.0">
<AttributeName Language="C#">[System.Diagnostics.CodeAnalysis.AllowNull]</AttributeName>
<AttributeName Language="F#">[<System.Diagnostics.CodeAnalysis.AllowNull>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.RequiresLocation]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.RequiresLocation>]</AttributeName>
</Attribute>
</Attributes>
</Parameter>
</Parameters>
<Docs>
<typeparam name="T">The elemental type of the managed pointers.</typeparam>
<param name="left">The first managed pointer to compare.</param>
<param name="right">The second managed pointer to compare.</param>
<summary>Determines whether the specified managed pointers point to the same location.</summary>
<returns>
<see langword="true" /> if <paramref name="left" /> and <paramref name="right" /> point to the same location; otherwise, <see langword="false" />.</returns>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="As<T>">
<MemberSignature Language="C#" Value="public static T? As<T> (object? o) where T : class;" FrameworkAlternate="net-5.0;net-7.0;net-8.0;net-9.0" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig !!T As<class T>(object o) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Runtime.CompilerServices.Unsafe.As``1(System.Object)" />
<MemberSignature Language="VB.NET" Value="Public Shared Function As(Of T As Class) (o As Object) As T" />
<MemberSignature Language="F#" Value="static member As : obj -> 'T (requires 'T : null)" Usage="System.Runtime.CompilerServices.Unsafe.As o" />
<MemberSignature Language="C++ CLI" Value="public:
generic <typename T>
 where T : class static T As(System::Object ^ o);" />
<MemberSignature Language="C#" Value="public static T As<T> (object o) where T : class;" FrameworkAlternate="net-6.0;netcore-1.0;netcore-1.1;netcore-3.0;netcore-3.1;netstandard-2.0" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime.CompilerServices.Unsafe</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.2.0</AssemblyVersion>
<AssemblyVersion>4.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.6.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.NullableContext(2)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.NullableContext(2)>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>T</ReturnType>
<Attributes>
<Attribute FrameworkAlternate="net-5.0">
<AttributeName Language="C#">[System.Diagnostics.CodeAnalysis.NotNullIfNotNull("o")]</AttributeName>
<AttributeName Language="F#">[<System.Diagnostics.CodeAnalysis.NotNullIfNotNull("o")>]</AttributeName>
</Attribute>
</Attributes>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="T">
<Constraints>
<ParameterAttribute>ReferenceTypeConstraint</ParameterAttribute>
</Constraints>
</TypeParameter>
</TypeParameters>
<Parameters>
<Parameter Name="o" Type="System.Object" />
</Parameters>
<Docs>
<typeparam name="T">The type which the object will be cast to.</typeparam>
<param name="o">The object to cast.</param>
<summary>Casts the given object to the specified type.</summary>
<returns>The original object, cast to the given type.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This API is used to cast an object to the given type, suppressing the runtime's normal type safety checks. It is the caller's responsibility to ensure that the cast is legal. No `InvalidCastException` will be thrown.
The behavior of `Unsafe.As<T>(o)` is only well-defined if the typical "safe" casting operation `(T)o` would have succeeded. Use of this API to circumvent casts that would otherwise have failed is unsupported and could result in runtime instability.
To help enforce correct usage, developers might consider using a standard cast or a debug-only assert in their code, as shown in the following examples.
```cs
void ReinterpretCastAndUse_Sample1(object o)
{
// Assume that we know through some other means that 'o' is a string,
// and we want our library's debug builds to verify this.
// One way to do this is through a standard-style cast.
// A standard-style cast will throw InvalidCastException at runtime if the cast fails.
// n.b. Casts of null objects to reference types will succeed.
#if DEBUG
string s = (string)o;
#else
string s = Unsafe.As<string>(o);
#endif
DoSomethingWith(s);
}
void ReinterpretCastAndUse_Sample2(object o)
{
// Another way to check this is through a debug-only assert.
// Failed assertions will trigger attached debuggers or terminate the application immediately.
// Calls to Debug.Assert are removed from release builds.
Debug.Assert(o is null or string, "Unsafe.As call below is illegal!");
string s = Unsafe.As<string>(o);
DoSomethingWith(s);
}
```
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="As<TFrom,TTo>">
<MemberSignature Language="C#" Value="public static ref TTo As<TFrom,TTo> (ref TFrom source);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig !!TTo As<TFrom, TTo>(!!TFrom& source) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Runtime.CompilerServices.Unsafe.As``2(``0@)" />
<MemberSignature Language="VB.NET" Value="Public Shared Function As(Of TFrom, TTo) (ByRef source As TFrom) As TTo" />
<MemberSignature Language="F#" Value="static member As : 'From -> 'o" Usage="System.Runtime.CompilerServices.Unsafe.As source" />
<MemberSignature Language="C++ CLI" Value="public:
generic <typename TFrom, typename TTo>
 static TTo % As(TFrom % source);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime.CompilerServices.Unsafe</AssemblyName>
<AssemblyVersion>4.0.2.0</AssemblyVersion>
<AssemblyVersion>4.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.6.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue RefType="Ref">
<ReturnType>TTo</ReturnType>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="TFrom">
<Attributes>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(2)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(2)>]</AttributeName>
</Attribute>
</Attributes>
</TypeParameter>
<TypeParameter Name="TTo">
<Attributes>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(2)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(2)>]</AttributeName>
</Attribute>
</Attributes>
</TypeParameter>
</TypeParameters>
<Parameters>
<Parameter Name="source" Type="TFrom" RefType="ref" Index="0" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-1.1;netcore-3.0;netcore-3.1;netstandard-2.0" />
</Parameters>
<Docs>
<typeparam name="TFrom">The type of managed pointer to reinterpret.</typeparam>
<typeparam name="TTo">The desired type of the managed pointer.</typeparam>
<param name="source">The managed pointer to reinterpret.</param>
<summary>Reinterprets the given managed pointer as a new managed pointer to a value of type <typeparamref name="TTo" />.</summary>
<returns>A managed pointer to a value of type <typeparamref name="TTo" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This API is conceptually similar to C++'s `reinterpret_cast<>`. It is the caller's responsibility to ensure that the cast is legal. No runtime check will be performed.
Only the managed pointer is reinterpreted. The referenced value itself will remain unchanged. Consider the following example.
```cs
int[] intArray = new int[] { 0x1234_5678 }; // a 1-element array
ref int refToInt32 = ref intArray[0]; // managed pointer to first Int32 in array
ref short refToInt16 = ref Unsafe.As<int, short>(ref refToInt32); // reinterpret as managed pointer to Int16
Console.WriteLine($"0x{refToInt16:x4}");
```
The output of this program depends on the endianness of the current machine. On big-endian architectures, this code outputs `0x1234`. On little-endian architectures, this code outputs `0x5678`.
When casting a managed pointer from a narrower type to a wider type, the caller must ensure that dereferencing the pointer will not incur an out-of-bounds access. The caller is also responsible for ensuring that the resulting pointer is properly aligned for the referenced type. For more information on alignment assumptions, see [ECMA-335](https://www.ecma-international.org/publications-and-standards/standards/ecma-335/), Sec. I.12.6.2 ("Alignment").
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="AsPointer<T>">
<MemberSignature Language="C#" Value="public static void* AsPointer<T> (ref T value);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig void* AsPointer<T>(!!T& value) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Runtime.CompilerServices.Unsafe.AsPointer``1(``0@)" />
<MemberSignature Language="F#" Value="static member AsPointer : 'T -> nativeptr<unit>" Usage="System.Runtime.CompilerServices.Unsafe.AsPointer value" />
<MemberSignature Language="C++ CLI" Value="public:
generic <typename T>
 static void* AsPointer(T % value);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime.CompilerServices.Unsafe</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.2.0</AssemblyVersion>
<AssemblyVersion>4.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.6.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="net-7.0;net-8.0;net-9.0">
<AttributeName Language="C#">[System.CLSCompliant(false)]</AttributeName>
<AttributeName Language="F#">[<System.CLSCompliant(false)>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.NullableContext(0)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.NullableContext(0)>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Void*</ReturnType>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="T">
<Attributes>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(2)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(2)>]</AttributeName>
</Attribute>
</Attributes>
</TypeParameter>
</TypeParameters>
<Parameters>
<Parameter Name="value" Type="T" RefType="ref">
<Attributes>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(1)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(1)>]</AttributeName>
</Attribute>
</Attributes>
</Parameter>
</Parameters>
<Docs>
<typeparam name="T">The elemental type of the managed pointer.</typeparam>
<param name="value">The managed pointer to convert.</param>
<summary>Converts a managed pointer into an unmanaged pointer.</summary>
<returns>An unmanaged pointer corresponding to the original source pointer.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Unmanaged pointers are not tracked by the .NET garbage collector. If the original managed pointer points within a GC-managed object, the caller must ensure that the source object is pinned. If the source object is not pinned and the GC relocates the object, dereferencing the unmanaged pointer could cause an access violation.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="AsRef<T>">
<MemberSignature Language="C#" Value="public static ref T AsRef<T> (void* source);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig !!T AsRef<T>(void* source) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Runtime.CompilerServices.Unsafe.AsRef``1(System.Void*)" />
<MemberSignature Language="F#" Value="static member AsRef : nativeptr<unit> -> 'T" Usage="System.Runtime.CompilerServices.Unsafe.AsRef source" />
<MemberSignature Language="C++ CLI" Value="public:
generic <typename T>
 static T % AsRef(void* source);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime.CompilerServices.Unsafe</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.2.0</AssemblyVersion>
<AssemblyVersion>4.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.6.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="net-7.0;net-8.0;net-9.0">
<AttributeName Language="C#">[System.CLSCompliant(false)]</AttributeName>
<AttributeName Language="F#">[<System.CLSCompliant(false)>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.NullableContext(0)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.NullableContext(0)>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue RefType="Ref">
<ReturnType>T</ReturnType>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="T">
<Attributes>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(2)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(2)>]</AttributeName>
</Attribute>
</Attributes>
</TypeParameter>
</TypeParameters>
<Parameters>
<Parameter Name="source" Type="System.Void*" />
</Parameters>
<Docs>
<typeparam name="T">The elemental type of the managed pointer.</typeparam>
<param name="source">The unmanaged pointer to convert.</param>
<summary>Converts an unmanaged pointer into a managed pointer to a value of type <typeparamref name="T" />.</summary>
<returns>A managed pointer to a value of type <typeparamref name="T" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The caller is responsible for ensuring that the resulting managed pointer is properly aligned for the referenced type. For more information on alignment requirements, see [ECMA-335](https://www.ecma-international.org/publications-and-standards/standards/ecma-335/), Sec. I.12.6.2 ("Alignment").
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="AsRef<T>">
<MemberSignature Language="C#" Value="public static ref T AsRef<T> (in T source);" FrameworkAlternate="net-5.0;netcore-3.0;netcore-3.1" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig !!T AsRef<T>([in]!!T& source) cil managed" FrameworkAlternate="net-5.0;net-7.0;net-8.0;net-9.0;netcore-3.0;netcore-3.1" />
<MemberSignature Language="DocId" Value="M:System.Runtime.CompilerServices.Unsafe.AsRef``1(``0@)" />
<MemberSignature Language="VB.NET" Value="Public Shared Function AsRef(Of T) (ByRef source As T) As T" />
<MemberSignature Language="F#" Value="static member AsRef : 'T -> 'T" Usage="System.Runtime.CompilerServices.Unsafe.AsRef source" />
<MemberSignature Language="C++ CLI" Value="public:
generic <typename T>
 static T % AsRef(T % source);" />
<MemberSignature Language="C#" Value="public static ref T AsRef<T> (ref T source);" FrameworkAlternate="net-6.0;netstandard-2.0" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig !!T AsRef<T>(!!T& source) cil managed" FrameworkAlternate="net-6.0;netstandard-2.0" />
<MemberSignature Language="C#" Value="public static ref T AsRef<T> (scoped in T source);" FrameworkAlternate="net-7.0" />
<MemberSignature Language="C#" Value="public static ref T AsRef<T> (scoped ref T source);" FrameworkAlternate="net-8.0;net-9.0" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime.CompilerServices.Unsafe</AssemblyName>
<AssemblyVersion>4.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.6.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue RefType="Ref">
<ReturnType>T</ReturnType>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="T">
<Attributes>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(2)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(2)>]</AttributeName>
</Attribute>
</Attributes>
</TypeParameter>
</TypeParameters>
<Parameters>
<Parameter Name="source" Type="T" RefType="ref" Index="0" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-3.0;netcore-3.1;netstandard-2.0">
<Attributes>
<Attribute FrameworkAlternate="net-5.0;net-6.0;net-7.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.IsReadOnly]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.IsReadOnly>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.RequiresLocation]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.RequiresLocation>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.ScopedRef]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.ScopedRef>]</AttributeName>
</Attribute>
</Attributes>
</Parameter>
</Parameters>
<Docs>
<typeparam name="T">The underlying type of the reference.</typeparam>
<param name="source">The read-only reference to reinterpret.</param>
<summary>Reinterprets the given read-only reference as a mutable reference.</summary>
<returns>A mutable reference to a value of type <typeparamref name="T" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This API is conceptually similar to C++'s `const_cast<>`. It is the caller's responsibility to ensure that no data is written to the referenced location. The runtime contains internal logic predicated on the assumption that readonly references truly are immutable, and callers who violate this invariant may trigger undefined behavior within the runtime.
`AsRef` is typically used for passing a readonly reference into methods like <xref:System.Runtime.CompilerServices.Unsafe.Add%2A>, which accept mutable managed pointers as arguments. Consider the following example.
```cs
int ComputeSumOfElements(ref int refToFirstElement, nint numElements)
{
int sum = 0;
for (nint i = 0; i < numElements; i++)
{
sum += Unsafe.Add(ref refToFirstElement, i);
}
}
```
If the input parameter is `ref readonly int refToFirstElement` instead of `ref int refToFirstElement`, the previous example will not compile, since readonly references cannot be used as arguments to `Add`. Instead, `AsRef` can be used to remove the immutability constraint and allow compilation to succeed, as shown in the following example.
```cs
int ComputeSumOfElements(ref readonly int refToFirstElement, nint numElements)
{
int sum = 0;
for (nint i = 0; i < numElements; i++)
{
sum += Unsafe.Add(ref Unsafe.AsRef(ref refToFirstElement), i);
}
}
```
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="BitCast<TFrom,TTo>">
<MemberSignature Language="C#" Value="public static TTo BitCast<TFrom,TTo> (TFrom source) where TFrom : struct where TTo : struct;" FrameworkAlternate="net-8.0" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig !!TTo BitCast<struct .ctor (class System.ValueType) TFrom, struct .ctor (class System.ValueType) TTo>(!!TFrom source) cil managed" FrameworkAlternate="net-8.0" />
<MemberSignature Language="DocId" Value="M:System.Runtime.CompilerServices.Unsafe.BitCast``2(``0)" />
<MemberSignature Language="VB.NET" Value="Public Shared Function BitCast(Of TFrom As Structure, TTo As Structure) (source As TFrom) As TTo" FrameworkAlternate="net-8.0" />
<MemberSignature Language="F#" Value="static member BitCast : 'From -> 'o (requires 'From : struct and 'o : struct)" Usage="System.Runtime.CompilerServices.Unsafe.BitCast source" FrameworkAlternate="net-8.0" />
<MemberSignature Language="C++ CLI" Value="public:
generic <typename TFrom, typename TTo>
 where TFrom : value class where TTo : value class static TTo BitCast(TFrom source);" FrameworkAlternate="net-8.0" />
<MemberSignature Language="C#" Value="public static TTo BitCast<TFrom,TTo> (TFrom source);" FrameworkAlternate="net-9.0" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig !!TTo BitCast<TFrom, TTo>(!!TFrom source) cil managed" FrameworkAlternate="net-9.0" />
<MemberSignature Language="VB.NET" Value="Public Shared Function BitCast(Of TFrom, TTo) (source As TFrom) As TTo" FrameworkAlternate="net-9.0" />
<MemberSignature Language="F#" Value="static member BitCast : 'From -> 'o" Usage="System.Runtime.CompilerServices.Unsafe.BitCast source" FrameworkAlternate="net-9.0" />
<MemberSignature Language="C++ CLI" Value="public:
generic <typename TFrom, typename TTo>
 static TTo BitCast(TFrom source);" FrameworkAlternate="net-9.0" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime.CompilerServices.Unsafe</AssemblyName>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="net-8.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.NullableContext(0)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.NullableContext(0)>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>TTo</ReturnType>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="TFrom">
<Constraints>
<ParameterAttribute>DefaultConstructorConstraint</ParameterAttribute>
<ParameterAttribute>NotNullableValueTypeConstraint</ParameterAttribute>
<BaseTypeName>System.ValueType</BaseTypeName>
</Constraints>
<Attributes>