Last active
June 26, 2020 20:02
-
-
Save JohnMGant/1a04c8cfacc35ce0a9a42b00020abca7 to your computer and use it in GitHub Desktop.
Adds an array of integers using a point (don't do this!)
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
| 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