Delegates and Events Questions and Answers

By
1. ) What do you mean by call-back method?                                                                 
In object -oriented programming, one object send to message to other objects,The methods are used to callback message are known as callback methods.
     C# implements the callback technique in much safer and more object oriented manner,using the help of delegate objects.

2. ) What is the 'type safe' information?                                                                          
  • Number of parameters
  • Types of parameters
  • Return type
  • Calling convention
3. ) What are the main purpose to use the delegate objects?                                      
  • Callback
  • Event Handling
4. ) What are class used for delegate declaration?                                                         
System.Delegate

5. ) What is delegate in c# ?                                                                                               
A delegate in c# is a class type object that is used to encapsulate the method call and invoke a method at the time of its creation.
Delegate means "a person acting for another person" or "a method acting for another method".

6. ) What are the steps involved for creating a delegate ?                                           
  • Delegate declaration
  • Delegate method definition
  • Delegate object declaration
  • Delegate invocation(calling)
7. ) Through delegate only that function can be called whose signature and Return type is same as delegate ?                                           
True 
More Details..
8. ) What is the syntax for declaration of the delegate ?                                             
<access-specifier><delegate keyword><return type><delegate-name><parameter-list>
Ex.
public delegate void del();

9. ) What are the modifier(access-specifier) used to control the accessibility of the delegate ?
  • Public
  • protected
  • internal
  • private
  • New
Note:-The new modifier is only used on delegates declared within another type.

10. ) Where we can define the delegates ?                                                                       
  • Inside a class
  • outside the class
  • As a top level object in a namespace
11. ) What are the delegate types implicitly defined in c# ?                                         
Sealed.

12. ) What is delegate method and how to declare it ?                                                  
A method whose references is encapsulated into a delegate instance is known as delegate methods.
                                                                                      OR
A method which will be called by the delegate ,is known as delegate methods.
Ex.
public class student
{
public void show()
{
messageBox.show("Hello Friends");
}
}

13. ) What is the delegate object declaration in c# ?                                                    
We have already seen,a delegate is a class type and behave like a class. 
Syntax:- 
delegate-name delegate-object = new delegate-name(expression)
Ex.
student obj =new student();
del delobj =new del(obj.show);

14. ) What is the delegate invocation in c# ?                                                                 
Syntax:-
delegate-object (parameter-list);
Ex
delobj();
15. ) What are the types of delegates in c# ?                                                                   
There are two types of delegate in c #.
  • Single cast delegate
  • Double cast delegate
16. ) What is the single cast delegate ?                                                                             
One delegate object can call only one method, is known as single cast delegate.

17. ) What is the multi cast delegate in c# ?                                                                    
One delegate object can call more than one method in sequence ,is known as  multicast delegate.

18. ) What is the anonymous  method in context of delegate?                                   
The collection of methods directly pass the delegate,is known as anonymous method.
More Details..

19. ) What is event in c#?                                                                                                    
A  Event is a kind of notification(information) giving one by one object to another object to perform task.
More Details..

20. ) What is the syntax of event declaration ?                                                              
<access-specifier><Event-keyword><Delegate-name><Event-name>
Ex.
public event del myevent;
More Details..

21. ) What is the Event handler in c# ?                                                                            
Event handler is a method which is used for handling the events.

22. ) Are events are fully based on the delegates ?                                                        
Yes.We can not handle the events without delegates

0 comments:

Post a comment

Powered by Blogger.