When would you use delegates in C#?
When would you use delegates in C#?
Here is an answer to the C# interview question "When would you use delegates in C#?":
Delegates in C# are used to pass methods as arguments to other methods or to store methods in variables. They are useful in several scenarios:
Delegates are commonly used in event handling. When an event occurs, the event source calls a method on the delegate, which in turn calls the event handler method that was assigned to the delegate by the event subscriber.
Delegates allow you to pass a method as an argument to another method. The method passed as an argument is called a callback method and is executed by the calling method when certain conditions are met.
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.