4 ms·
> Do you have any examples? Sure, write a self-executing function in C#.
by Touche 13y ago
> Do you have any examples?
Sure, write a self-executing function in C#.
- paulmcpazzi 13y ago((Action)(() => Console.WriteLine("Hello")))(); or new Action(() => Console.WriteLine("Hello"))(); Yeah, it's verbose because you have to cast the lambda expression before executing it, but honestly I don't know any case where a self executing function can be useful in C#.
- Touche 13y agoNot too bad. Actions return null though. How about a self-executing function that returns a value? This is useful for assigning values to variables. IIRC it's going to start getting more ugly from here.
- noblethrasher 13y ago(new Func<int>(() => 2))();