Skip to content

Instantly share code, notes, and snippets.

@JohnMGant
Last active June 26, 2020 20:02
Show Gist options
  • Select an option

  • Save JohnMGant/1a04c8cfacc35ce0a9a42b00020abca7 to your computer and use it in GitHub Desktop.

Select an option

Save JohnMGant/1a04c8cfacc35ce0a9a42b00020abca7 to your computer and use it in GitHub Desktop.
Adds an array of integers using a point (don't do this!)
internal unsafe class ArrayPointerAdder : IIntegerAdder
{
public int Add(int[] values)
{
int sum = 0;
int count = values.Length;
fixed (int *p = values)
{
for (int i = 0; i < count; i++)
{
sum += p[i];
}
}
return sum;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment