Skip to content

Instantly share code, notes, and snippets.

@Scooletz
Created December 21, 2019 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Scooletz/3e1c31f87d50781dd1cb6cccfb2378fb to your computer and use it in GitHub Desktop.
Save Scooletz/3e1c31f87d50781dd1cb6cccfb2378fb to your computer and use it in GitHub Desktop.
A simple case of bound checks skipped with ref and Unsafe.Add
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