python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 7, Interview Questions Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
delegate in c# with example

Delegates in C# Example

The basic examples of Delegates using in C# .Net as given below,

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace delegateExample
    public delegate int AddByDelegate(int var1, int var2);

    public class DelegateClass
        public static int Add(int a, int b)
            return a + b;
        static void Main(string[] args)
            //Creating the Delegate Instance
            AddByDelegate delObject = new AddByDelegate(Add);

            Console.Write("Please enter value");
            int num1 = Int32.Parse(Console.ReadLine());
            int num2 = Int32.Parse(Console.ReadLine());

            // Here method Add is call.
            int Result = delObject(num1, num2);
            Console.WriteLine("Result :" + Result);
//The Delegate - OutPut

Result : 30


Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - and
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like Powered by Blogger.
ASK Questions