Beginning C# 7 Hands-On:Advanced Language Features
上QQ阅读APP看书,第一时间看更新

Initializing a collection of integers to their array and displaying the results

Now, double-click on the Display Values button and go into Default.aspx.cs. Delete the Page_Load block. Next, between the set of curly braces beneath the line beginning with protected void Button1_Click..., enter the following:

GenericsClass<int> ints = new GenericsClass<int>(new int[] { 1, 2, 3, 4, 5 });

You can see in this line that we are basically initializing a collection of integers to their array.

Now, you can display this. So, for example, you can enter the following below this line:

sampLabel.Text += ints.DisplayValues();

Notice that the GenericsClass which we have constructed is operating in integers, but it can operate equally well on any other data type.