Created
December 21, 2019 14:10
-
-
Save Scooletz/3e1c31f87d50781dd1cb6cccfb2378fb to your computer and use it in GitHub Desktop.
A simple case of bound checks skipped with ref and Unsafe.Add
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.CompilerServices; | |
public class C | |
{ | |
public static void A(Span<int> a) | |
{ | |
a[0] = 1; | |
a[1] = 2; | |
a[2] = 3; | |
} | |
public static void A(ref int a) | |
{ | |
a = 1; | |
Unsafe.Add(ref a, 1) = 2; | |
Unsafe.Add(ref a, 2) = 3; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment