C#的委托(delegate)和事件(event)

有一些概念是看过一次记得,久不接触就忘了的,但是以后要重新捡起,又要花些时间看书,所以记下来为了巩固。

1. 申明Deleagate:其实背后是IL编译器为你创造了一个封装函数指针的类,这个类名就是你申明时所用的函数名,例如Delegate void AddDelegate(int, int)。winForm技术中喜欢将AddDelegate称为AddEventHandler,所以也就有了那么多EventHandler。

2. 申明Event::当Event和前面申明的委托,也就是AddEventHandler联合申明一个事件,例如 public event AddEventHandler addevent, 这个IL编译出来的的是包含函数指针列表的类实例。而addevent()调用,就变成函数列表的调用,官方文字称诸多订阅该事件的委托实例的调用。所以订阅的语句:addevent+= new AddEventHandler(clientDimAdd) ,也就是将这个回调函数加入到列表中,以便事件触发时依次调用。

831人评论了“C#的委托(delegate)和事件(event)”

  1. To get your Epson printer back online, first ensure it’s powered on and properly connected via Wi-Fi or USB. Check for error messages on the display panel. On your computer, go to printer settings and disable “Use Printer Offline.” Restart the printer, computer, and router. If needed, reinstall or update the printer driver from Epson’s website. Use Epson’s diagnostic tools for troubleshooting. Ensuring a stable connection and correct settings typically resolves most offline printer issues quickly.

  2. Rabby Wallet is a secure and user-friendly crypto wallet designed for seamless interaction with decentralized applications (dApps). It supports multiple blockchains, making crypto management easier than ever. With features like built-in risk alerts, token insights, and smooth transaction signing, Rabby Wallet ensures safe and efficient Web3 experiences. Whether you’re a beginner or an experienced trader, Rabby Wallet offers the perfect blend of convenience, transparency, and security for all your crypto needs.

  3. Ledger Live Desktop is the best platform for safely handling your cryptocurrency. With complete control over your private keys, you may purchase, sell, exchange and stake more than 5500 coins and tokens by connecting your Ledger hardware wallet. From a single, reliable desktop software, enjoy unmatched security, simple portfolio management and effortless DeFi access.
    For more Information:
    https://sites.google.com/ledgercomstart.com/ledger-live-desktop/home

  4. Hermosos cachorros para adopción. El mejor lugar para conseguir tus adorables y bien entrenados cachorros.
    Al adoptar, no solo consigues un amigo fiel, sino que también ayudas a combatir la sobrepoblación en los refugios,
    dándole una segunda oportunidad a un cachorro que, de otro modo, podría enfrentar un futuro sombrío.
    Es fundamental considerar diversos factores, como la raza, el tamaño y el temperamento del cachorro,
    para asegurar que se adapte a tu estilo de vida.
    https://xn--cachorrosparaadopcin-t8b.com/
    https://xn--cachorrosparaadopcin-t8b.com/otros-perros-de-raza-pura/

  5. Having trouble被公 logging into Crypto.com? Discover solutions for common login issues like password errors, 2FA problems, and app glitches. Learn how to reset your credentials, update the app, or contact support. This quick guide helps you fix login problems and regain secure access to your Crypto.com account on both mobile and desktop platforms.

    Crypto.com login issues | Crypto.com login issue

发表评论

邮箱地址不会被公开。