Function memoization in C#