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

Hardcoding the values

Now, back in Default.aspx, go to the Design view and double-click on the Exchange and Compare button. All we will do is to hardcode the values to save time. We don't have to read them from the user. Of course, you can, if you want to, by putting in two boxes and process that using double convert.

Now, in Default.aspx.cs, between a set of curly braces below the line beginning with protected void Button1_Click..., enter the following lines:

double x = 25, y = 34;

Then use sampLabel.Text to display the original values on this screen, first displaying the value of x and then displaying the value of y:

sampLabel.Text = $"x={x}, y={y}";

Next, to do the swapping of the values. Enter the following:

GenMethods.Swap<double>(ref x, ref y);  

First, you enter the name of class and then the function, which is Swap. You will see that <T> can now be replaced with <double>, because we are swapping doubles. Then, you'll put in ref x and ref y.

Because we are using ref, the values of x and y have to be initialized and further now we can display them again, but swapped, as shown here:

sampLabel.Text += $"<br>x={x}, y={y}";
主站蜘蛛池模板: 志丹县| 隆昌县| 磐安县| 陆丰市| 遂昌县| 蓝田县| 绥滨县| 株洲市| 文山县| 石家庄市| 西充县| 务川| 天镇县| 嘉禾县| 邵东县| 万年县| 武穴市| 织金县| 湛江市| 商南县| 甘肃省| 玛多县| 白玉县| 福泉市| 连平县| 肇源县| 新和县| 新源县| 罗田县| 鸡西市| 湘潭市| 阿巴嘎旗| 皮山县| 茶陵县| 中阳县| 库车县| 厦门市| 瑞安市| 清水河县| 陆良县| 云和县|