.net - C# - Passing Delegate as a parameter to a method -
I am trying to get acquainted with the concept of delegates in C #. I have created this console application so far:
Program.cs Arithmetic operations.cs As you can see from the code, I am using a static class named ArithmeticOperation.cs to perform some arithmetic functions. The ConvertResultToString method takes one of the arithmetic operations methods in the form of a parameter to display results as a string. Unfortunately, my code does not compile, it is giving me the following error: The error is being given on this line: Can you please help me solve this problem because I do not have much experience with the representatives? In fact, I have created this application to learn about the delegates. To pass a representative, you must pass ...
using the system; Namespace Delegatesest {Class Program {Static Wide Men (String [] AGRs) {Arithmetic Operation. Arrow Deedal Acquired, New Arithmetic Operation. Arop Dale (Arthmetic Operation. Addition); Console.light line (Arithmetic Operation. Convert ResultTostring (Extra Delegate (10, 5)); Console.ReadKey (); }}}
using the system; Namespace Delegates Test {Public Static Class Arithmetic Operation {Public Deliveries Aropadale (Int X, Int Y); Public Stable String Convert ResultTostring (AropDL Dell) {String result = string.format ("{0} is the result of the operation {1}", Dell method .name, Dell.tostring ()); Return result; } Public static integration (int x, int y) {return x + y; } Substitution of public fixed integer (int x, int y) {return x - y; } Public constant int multiplication (int x, int y) {return x * y; } Public stable int division (int x, int y) {return x / y; }}}
Logic '1': 'del' from 'deli' Arithmetic Operation Arrow Deed can not be changed
console. Virus Line (Arithmetic Operation. Convert ResultTostring (Extra Detolegate (10, 5)));
additional delay (10, 5)) one
additionDelegate is actually a
addition function. Therefore, the result is an integer.
additionDelegate instead of
additionDelegate (10, 5) . But, in this case, the result of the operation will not be available in
ConvertResultToString unless you call it there. Public Static String Convert ResultTostring (Arope del Dell) {string result = string.format ("{0} is the result of operation {1}", del. Method.Name, del (10 , 5). Ostring ()); Return result; }
console WrightLine (ArithmeticOperation.ConvertResultToString (additionDelegate));
Comments
Post a Comment