如何从字符串数组转换为sortedSet
本文关键字:转换 sortedSet 数组 字符串 | 更新日期: 2023-09-27 18:00:09
我需要提取(简单的部分)一个整数列表,该列表通过从someString.split(分隔符)获得的字符串数组给出。我需要的是将得到的数组(字符串)放在sortedSet中。我该如何转换?我尝试过不同的东西。
当前代码在VB 中
Dim _ports As New SortedSet(Of Integer) = Array.ConvertAll(portString.Split(","),Integer.Parse())
我试过了,但不正确。我知道迭代每一项并将其放入sortedSet中很简单,但有没有直接的方法呢。
C#-如果将int.Parse
传递给它,Enumerable.Select
将执行字符串到整数的转换。
var resultingArray = new SortedSet<int>(portString.Split(',').Select(int.Parse));
因此,将Alexei Levenkov写的内容翻译成VB将是:
Dim resultingArray = New SortedSet(Of Integer)(portString.Split(","c).Select(AddressOf Integer.Parse))