Skip to content

Instantly share code, notes, and snippets.

@JohnMGant
Created November 17, 2020 21:54
Show Gist options
  • Select an option

  • Save JohnMGant/0ddebb95ddb5d4535502905007ab565f to your computer and use it in GitHub Desktop.

Select an option

Save JohnMGant/0ddebb95ddb5d4535502905007ab565f to your computer and use it in GitHub Desktop.
internal unsafe class PointerHeadTailAdder : IIntegerAdder
{
public int Add(int[] values)
{
fixed (int* head = values)
{
return AddImplementation(head, values.Length);
}
}
private static int AddImplementation(int *head, int length)
{
if (length == 0)
{
return 0;
}
return *head + AddImplementation(++head, --length);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment