Consider this simple .js code:
const createCounter = () => {
let value = 0;
return {
increment: () => { value += 1 },
decrement: () => { value -= 1 },
logValue: () => { console.log(value); }
}
}
// Usage
const { increment, decrement, logValue } = createCounter();
I'm pretty sure c# support first class function, note that I don't want to use classes to remake the code above. What is the equivalent closure in c#?
I have made this:
public Func<WhatType?> CreateCounter = () => {
var value = 0;
return what?
}
Map
of functions. I don't know if there's such a thing as destructuring in C# (or similar) – Atalee