none
Delegate usefulness RRS feed

  • Question

  • Hey everyone,

    I am the newest member of this forum right now.

    I have a question about usefulness of delegates:

    Delegates are very useful when you multicast few methods. I agreed so far. However what would happen if i put these all methods in one method and use it's reference like single delegates. Is it same thing ?

    Cheers,

    Sunday, February 23, 2020 7:08 PM

All replies

  • I can't tell what you mean by "put these all methods in one method".  Can you maybe give an example of what you mean?

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Sunday, February 23, 2020 7:34 PM
  • I have a question about usefulness of delegates:

    Delegates are very useful when you multicast few methods. I agreed so far. However what would happen if i put these all methods in one method and use it's reference like single delegates. Is it same thing ?

    Hi, alper_oguzhan.  I'm not really clear on what your actual question is here.

    Delegates are useful for multicasting:  YES!

    Delegates are useful for asynchronous execution without threading:  YES!

    Delegates are useful for asynchronous-to-synchronous Invocation/marshalling (ie thread safety) with and without threading:  YES!

    What is meant by "put all methods in one method and use it like a single delegate" - just having 1 function and 1 delegate?  If so, then that's exactly how delegates are used to create async and async-Invocable/thread-safe code.

    If this isn't what you mean, please explain or provide a bit of code showing what you're asking.

    Sunday, February 23, 2020 7:50 PM
  • Hello,

    It's difficult to know what you mean, can you provide an abstract example and/or relate to one of these examples?

    https://dotnettutorials.net/lesson/multicast-delegate-csharp/


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Sunday, February 23, 2020 9:35 PM
    Moderator
  • If you are the only person writing all the programs then it will be difficult to understand the value of many things that experienced developers do. Also there are some things (such as properties) that are difficult to understand the value of in simple programs. You need to get more experience and you need to think in terms of multiple developers. I think it is then easy to understand the value of segregating things. You will get the impression that experienced programmers do things the hard way. Well some might make things too complicated but when something such as multicast delegates is done by most all of the experienced developers then you as a beginner can simply assume they have a good reason to do it and you will understand after you get more experience. As a beginner there is so much to learn and it is beneficial to prioritize what is important to learn. It is important for you to learn how to use delegates but for now instead of being pro-active to understand why, it is better to be patient for the opportunity to understand why.


    Sam Hobbs
    SimpleSamples.Info

    Monday, February 24, 2020 3:20 AM
  • Delegates allow methods to be passed as parameters.
    Delegates are type safe function pointer.
    Delegate instances attach or detach a method at run time making it more dynamic and flexible to use.
    Delegates can invoke more than one method using the Multicast feature.
    Delegates are of reference types.
    
    look the url for delegate  and events
    https://www.akadia.com/services/dotnet_delegates_and_events.html
    
    Best Regards
    Laxmidhar sahoo

    Monday, February 24, 2020 5:42 AM
  • Hi,

    Has your problem been solved?

    If so, please click "Mark as answer" to the appropriate answer, so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, February 28, 2020 10:00 AM