You can use the Action delegate to pass a method as a parameter without explicitly declaring a custom delegate. ' This code will produce output similar to the following: ' Display the contents of the list using the Print method. (* This code will produce output similar to the following: The following demonstrates the lambda expression feature of F# Display the contents of the list using the print function. F# provides a type alias for as ResizeArray. * This code will produce output similar to the following: to display the contents of the list to the console. The following demonstrates the anonymous method feature of C# Display the contents of the list using the Print method. Similarly, in the C# example, an Action delegate is not explicitly instantiated because the signature of the anonymous method matches the signature of the Action delegate that is expected by the List.ForEach method. Instead, it passes a reference to a method that takes a single parameter and that does not return a value to the List.ForEach method, whose single parameter is an Action delegate. Note that the example does not explicitly declare an Action variable. In addition, the C# example also demonstrates the use of anonymous methods to display the contents to the console. In this example, the Print method is used to display the contents of the list to the console. The following example demonstrates the use of the Action delegate to print the contents of a List object. The parameter of the method that this delegate encapsulates.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |