- Beginning C# 7 Hands-On:Advanced Language Features
- Tom Owsiak
- 221字
- 2021-07-02 15:29:20
Running the program
Now, let's take a look at the effects. For this, launch the program in your browser. Click on the Summarize button. The results are shown in Figure 4.4.3:

As you can see, 4+5=9, 4/5=0.8, and 4*5=20. So, it's working as expected. The public delegate void Summarize<T>(T x, T y); line is a single, generic delegate and, because it has T there and not a fixed data type such as integer or double, it can operate on different data types.
Now, if you take your Default.aspx.cs page and search for all occurrences of double and replace them with int, seven occurrences will be replaced. If you run the code again, you'll see that it works equally well. Just to illustrate the point further, replace int with decimal and again seven occurrences are replaced. Now, it will be operating in decimal types and, if you click on the Summarize button once more, you'll see that it works equally well.
So, there you have a generic delegate. Remember, with a single button click, you can basically invoke a whole list of functions by chaining them together through the s delegate, which is of the Summarize type, which is generic so that it can operate on different data types equally well.
- Vue 3移動Web開發與性能調優實戰
- Learn ECMAScript(Second Edition)
- Python 深度學習
- C#程序設計(慕課版)
- Web Application Development with R Using Shiny(Second Edition)
- INSTANT Sencha Touch
- C語言程序設計實踐教程
- 游戲程序設計教程
- 單片機應用技術
- MATLAB 2020從入門到精通
- 低代碼平臺開發實踐:基于React
- Microsoft Dynamics AX 2012 R3 Financial Management
- Visual Studio 2015高級編程(第6版)
- 零基礎學C語言(升級版)
- Mastering Elixir