C# Programming - Delegates - Discussion

Discussion :: Delegates - General Questions (Q.No.5)

5. 

Which of the following is the correct way to call the function MyFun() of the Sample class given below?

class Sample
{
    public int MyFun(int i)
    {
        Console.WriteLine("Welcome to IndiaBIX.com !" );
        return 0;
    }
}

[A].
delegate void del(int i);
Sample s = new Sample();
deld = new del(ref s.MyFun);
d(10);
[B].
delegate int del(int i);
Sample s = new Sample(.);
del = new delegate(ref MyFun);
del(10);
[C].
Sample s = new Sample();
delegate void del = new delegate(ref MyFun);
del(10);
[D].
delegate int del(int i);
del d;
Sample s = new Sample();
d = new del(ref s.MyFun);
d(10);

Answer: Option D

Explanation:

No answer description available for this question.

Anubhav Singh said: (Jan 24, 2016)  
What is this "ref" doing here?

Aaron T said: (Feb 22, 2016)  
Remove 'ref'.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.