anonymous delegates in C#

Yes. In .NET 3.5 you can use Func and Action delegates. The Func delegates return a value, while Action delegates return void. Here is what the type names would look like: System.Func<TReturn> // (no arg, with return value) System.Func<T, TReturn> // (1 arg, with return value) System.Func<T1, T2, TReturn> // (2 arg, with return value) … Read more

C# Cannot use ref or out parameter inside an anonymous method body

Okay, I’ve found that it actually is possible with pointers if in unsafe context: public static class IntEx { unsafe public static Action CreateIncrementer(int* reference) { return () => { *reference += 1; }; } } However, the garbage collector can wreak havoc with this by moving your reference during garbage collection, as the following … Read more

tech