|
|
Title | Initialize an array with a range of values or a repeated value in Visual Basic .NET (version 2008 or later) |
Description | This example shows how to initialize an array with a range of values or a repeated value in Visual Basic .NET (version 2008 or later). |
Keywords | initialization, initialize array, range, repeated values, VB.NET, Visual Basic .NET, Visual Basic 2008 |
Categories | Tips and Tricks, VB.NET |
|
|
The Enumerable class provides shared methods that can initialize an array to a range of values or a repeated set of values. When the program starts, it uses the following code to make an array holding the values 101 through 120 and a second array holding 20 entries all set to 13. It sets the DataSource of two ListBoxes to these arrays so you can see the values.
|
|
Dim range_values() As Integer
range_values = Enumerable.Range(101, 20).ToArray()
lstRange.DataSource = range_values
Dim repeat_values() As Integer
repeat_values = Enumerable.Repeat(Of Integer)(13, _
20).ToArray()
lstRepeat.DataSource = repeat_values
|
|
|
|
|
|