c# - Understanding Lambda expressions and delegates -


I'm trying to understand it for a while (online blogs and artikeling), but still unsuccessful

What are the reps? What are lambda expressions? Profit and loss of both?

Representative, they are the methods that you can use in the form of variables Can, like strings etc. For example, you can declare a representative method with an argument:

 Free representative OneArgumentDelegate (string argument); 

It does not do anything, like many interfaces if you have an argument in any class, then an argument like this:

 Zero Certain Methods (String Some Agreement) {} 

This can be assigned the signature of the matches representative, and thus a variable of its type:

An Official DelegateThis IsAviable = New OneArgumentDelegate (SomeMethod); OneArgumentDelegateThisIsAlsoAvariable = SomeMethod; // Shortcodes also work

These can be passed as arguments in the form of methods and can be implemented:

 void main () {DUSTF ( Printstring); } Zero printstring (string text) {Console.WriteLine (text); } Zero Dustf (Forest Agreement Delegate Action) {Action ("Hello!"); } 

This Hello! will .

There is a shortcut to LMDa Expressress DUSTF (printstring) so that you do not have to make a method for every representative variable you are going to use you have a 'temporary' 'Method which has passed on the method. It works like this:

 two stuff (string text => console.lightline (text)); // Single Line Dustf (String Text => // Multi Line {Console.Published (text); Console.WeDline (Text);}); 

Lembda expressions are only a rhythm, you can also have a different method and pass it. I hope you understand it better; -)


Comments