官术网_书友最值得收藏!

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:

Figure 4.4.3: The results of running our program for this project

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.

主站蜘蛛池模板: 高密市| 若羌县| 开化县| 治多县| 象山县| 旌德县| 德令哈市| 黄山市| 嫩江县| 平果县| 民乐县| 五台县| 长子县| 分宜县| 西峡县| 大悟县| 抚宁县| 木里| 白山市| 藁城市| 汾西县| 壤塘县| 南平市| 隆德县| 闸北区| 香港| 红桥区| 兴安盟| 右玉县| 兴仁县| 江源县| 治县。| 乌鲁木齐市| 威远县| 宁城县| 万源市| 韩城市| 武川县| 磐安县| 韶山市| 平舆县|