Dr. Code
Dr. Code

Reputation: 53

How to generate a list with a specific range of numbers

Dim myList As New List(Of Integer)(New Integer() {1001, 1006, 1011, 1016, 1021, 1026, 1031, 1036, 1041, 1046, 1051, 1056, 1061, 1066, 1071})

How can I reduce the code above?

Upvotes: 0

Views: 1489

Answers (1)

Steve
Steve

Reputation: 216273

The initialization of the first list could be done in this way

Dim init As Integer = 1001
Dim myList As IEnumerable(Of Integer) = Enumerable.Range(start:=0, count:=15).
                                        Select(Function(x) init + (x * 5))

The creation of the string result could be done with String.Join

Dim result = String.Join(Environment.NewLine, myList)
Console.WriteLine(result)

Upvotes: 3

Related Questions