C
C#•9mo ago
duaalk

Lambda expression and arrow function

is lambda expression similar to arrow function in JS?
3 Replies
canton7
canton7•9mo ago
They're similar, yes
SoftwareEngineer666👿⸸⸸⸸
Yes. If you want to parse lambda's around in C# you can either write a delegate or you can use built in Action and Func delegates. The last generic provided to Func is the return type. Action has no return type. So for example Action<string, int> theMethod = (aString, anInt)=>{ ...Do something}; Func<string, bool> = (stringIn)=>{ do something..... return true}; kinda thing. Or you could write a delegate public delegate bool MyDelegate(string aParameter, long anotherParameter); and use it like MyDelegate d = (aString, anotherParameter)=> { .... do something}. And you can miss off the curley brackets if you can write the function in a single line. If you want to use ref and out, you can do that if you write a delegate. But Action and Func wont let you do that.
duaalk
duaalkOP•9mo ago
thanks that is very helpful
Want results from more Discord servers?
Add your server