Avoid those unnecessary for-loops…

One thing that makes my - and others - code look ugly are all those for-loops repeatedly embedded into the code.

A typical example ias converting a string of comma seperated numbers into an array of integers. Here’s how to do it in one statement, without any loop:

Dim str As String = "1,2,3,4,5"
Dim ints As Integer() = Array.ConvertAll(Of String, Integer)(str.Split(","), _
    AddressOf Convert.ToInt32)
- petter


Leave a comment...

Powered by WordPress. Entries (RSS) and Comments (RSS).