delegates c programming questions

6.

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

class Sample
{
public void MyFun(int i, Single j)
{
Console.WriteLine(“Welcome to IndiaBIX !”);
}
}

A.

delegate void del(int i);
Sample s = new Sample();
del d = new del(ref s.MyFun);
d(10, 1.1f);

B.

delegate void del(int i, Single j);
del d;
Sample s = new Sample();
d = new del(ref s.MyFun);
d(10, 1.1f);

C.

Sample s = new Sample();
delegate void d = new del(ref MyFun);
d(10, 1.1f);

D.

delegate void del(int i, Single]);
Sample s = new Sample();
del = new delegate(ref MyFun);
del(10, 1.1f);

Answer & Explanation

Answer: Option B

Explanation:

No answer description available for this question. Let us discuss.
View Answer Workspace Report Discuss in Forum
7.

Which of the following statements are correct about a delegate?

Inheritance is a prerequisite for using delegates.
Delegates are type-safe.
Delegates provide wrappers for function pointers.
The declaration of a delegate must match the signature of the method that we intend to call using it.
Functions called using delegates are always late-bound.

A.     1 and 2 only
B.     1, 2 and 3 only
C.     2, 3 and 4 only
D.     All of the above
E.     None of the above
Answer & Explanation

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.
View Answer Workspace Report Discuss in Forum
8.

Which of the following statements are correct about delegates?

Delegates are not type-safe.
Delegate is a user-defined type.
Only one method can be bound with one delegate object.
Delegates can be used to implement callback notification.
Delegates permit execution of a method on a secondary thread in an asynchronous manner.

A.     1 and 2 only
B.     1, 2 and 3 only
C.     2, 4 and 5 only
D.     4 and 5 only
E.     All of the above
Answer & Explanation

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.
View Answer Workspace Report Discuss in Forum
9.

Which of the following statements are correct about delegates?
A.     Delegates cannot be used to call a static method of a class.
B.     Delegates cannot be used to call procedures that receive variable number of arguments.
C.     If signatures of two methods are same they can be called through the same delegate object.
D.     Delegates cannot be used to call an instance function. Delegates cannot be used to call an instance subroutine.
Answer & Explanation

Answer: Option B

Explanation:

No answer description available for this question. Let us discuss.
View Answer Workspace Report Discuss in Forum
10.

Which of the following are the correct ways to declare a delegate for calling the function func() defined in the sample class given below?

class Sample
{
public int func(int i, Single j)
{
/* Add code here. */
}
}

A.     delegate d(int i, Single j);
B.     delegate void d(int, Single);
C.     delegate int d(int i, Single j);
D.     delegate void (int i, Single j);
E.     delegate int sample.func(int i, Single j);
Answer & Explanation

Answer: Option C

Explanation:

No answer description available for this question.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>