Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using revision;
- public class Program
- {
- delegate int CalculateDelegate(int x, int y);
- static void Main(String[] args){
- Calculate(10, 5, Add);
- CalculateDelegate dlg = Substract;
- Calculate(10, 5, dlg);
- CalculateDelegate dlg2 = new CalculateDelegate(Multiply);
- Calculate(10, 5, dlg2);
- Calculate(10, 5, delegate(int x , int y) { return x / y; });
- Calculate(10 , 5 , ( x , y ) => x % y); // lampda expression
- // can call multiple functions
- dlg += Add;
- dlg += Multiply;
- dlg += Divide;
- dlg -= Substract;
- }
- static int Calculate(int x, int y , CalculateDelegate dlg) {
- int result = dlg(x, y);
- Console.WriteLine(result);
- return result;
- }
- static int Add(int x, int y){
- Console.WriteLine("Add");
- return x + y;
- }
- static int Substract(int x, int y){
- Console.WriteLine("Substract");
- return x - y;
- }
- static int Multiply(int x, int y) {
- Console.WriteLine("Multiply");
- return x * y;
- }
- static int Divide(int x, int y) {
- Console.WriteLine("Divide");
- return x / y;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement