How would I implement this in C#?