Вопрос

I need to extract(the easy part) a list of integers given through an array of strings gotten from: someString.split(separator) What I need is to put that resulting array(string) in a sortedSet How do I convert that? I've tried different things.

the current code is in VB

Dim _ports As New SortedSet(Of Integer) = Array.ConvertAll(portString.Split(","),Integer.Parse())

I've tried this but is not correct. I know that is simple to iterate though every single item and put it into the sortedSet but, is there any way to do it directly.

Это было полезно?

Решение

C# - Enumerable.Select will do conversion of string to integer if you pass int.Parse to it.

var resultingArray = new SortedSet<int>(portString.Split(',').Select(int.Parse));

Другие советы

So, translating what Alexei Levenkov wrote to VB would be:

Dim resultingArray = New SortedSet(Of Integer)(portString.Split(","c).Select(AddressOf Integer.Parse))
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top