- Beginning C# 7 Hands-On:Advanced Language Features
- Tom Owsiak
- 201字
- 2021-07-02 15:29:17
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}";
- Qt 5 and OpenCV 4 Computer Vision Projects
- Mastering ServiceStack
- Mastering Objectoriented Python
- 深入淺出Java虛擬機:JVM原理與實戰
- 三維圖形化C++趣味編程
- MATLAB應用與實驗教程
- C#程序設計教程
- 零基礎學Python網絡爬蟲案例實戰全流程詳解(高級進階篇)
- 飛槳PaddlePaddle深度學習實戰
- 深入理解Elasticsearch(原書第3版)
- Solr Cookbook(Third Edition)
- Flask Web開發:基于Python的Web應用開發實戰(第2版)
- Android移動應用項目化教程
- Building Microservices with Go
- MySQL數據庫教程(視頻指導版)