For the purpose of mvvm learning, review the anonymous method and lambda expressions. Because there are few examples used previously, they are not very skilled. Baidu-related knowledge, I wrote this demo to demonstrate how to use it in a simple way.
Here, the emphasis is on lambda expressions in LINQ.
VaRFileslookup = files. tolookup (F => F. substring (F. lastindexof ('.'). Toupper ());
There are some differences. Use them in two different ways.
Debuglzq has written all the words to be written in the demo comments. There are many similar things on the Internet, so there is no ink here, as shown below:
Using System; Namespace Anonymous functions and lambda expressions { Class Program { /// <Summary> /// Func and action classes are special types that allow you to use a delegate without specifying a custom delegate type. They can be used throughout the. NET Framework. /// /// Lambda expressions have widely replaced anonymous methods because they are introduced from C #3.0. Lambda expressions have many of the same functions as anonymous methods, but they are easier to use. /// </Summary> /// <Param name = "ARGs"> </param> Static Void Main ( String [] ARGs ){ // Action delegate encapsulate methods that do not return results. In other words, this delegate can only be used for the methods defined with the void keyword. Action < Int , Int > FUNA = Delegate ( Int X, Int Y) {console. writeline (x + y );}; // Anonymous Method Action < Int , Int > Funb = ( Int X, Int Y) => { Int Z = x + y; console. writeline (z );}; // Lambda expressions // Output FUNA ( 3 , 4 ); Funb ( 3 , 4 ); Console. readkey (); // In addition to returning results, the system. func delegate is identical to the action delegate. The simplest func implementation has no parameters. Func < Int , Int , Int > Fun1 = Delegate ( Int X, Int Y ){ Return X * Y ;}; // Anonymous Method Func < Int , Int , Int > Fun2 = ( Int X, Int Y) => { Return X * Y ;}; // Lambda expressions // Output Console. writeline (fun1 ( 3 , 4 ); Console. writeline (fun2 ( 3 , 4 ); Console. readkey ();}}}
A picture is better than a thousand words,ProgramRun the following command: