[英]System.Object[] can't be converted to System.String[]
I'm trying to convert the C# line我正在尝试转换 C# 行
string[] phrases = text.Split (new[] { '\"' }, StringSplitOptions.RemoveEmptyEntries);
to VB.NET.到 VB.NET。
My attempt was我的尝试是
Dim phrases() As String = text.Split (New Object() { """"c }, StringSplitOptions.RemoveEmptyEntries)
However, I'm getting the error "System.Object[] can't be converted to System.String[]".但是,我收到错误“System.Object[] 无法转换为 System.String[]”。
What I'm doing wrong, please?请问我做错了什么?
You can use any online C# to VB converter and you'll get this:你可以使用任何在线 C# 到 VB 转换器,你会得到这个:
Dim phrases As String() = text.Split(New String() {""""C}, StringSplitOptions.RemoveEmptyEntries)
So the wrong part was using Object().所以错误的部分是使用 Object()。
As Plutonix mentioned in his comment, the first parameter is a char array (new[] { '\\"' } is nothing if not a char array), so perhaps it makes some sense to use a char array?正如 Plutonix 在他的评论中提到的,第一个参数是一个 char 数组(new[] { '\\"' } 如果不是一个 char 数组,则什么都不是),所以使用 char 数组也许有意义?
Dim phrases() As String = text.Split(New Char() {""""c}, StringSplitOptions.RemoveEmptyEntries)
Now in VB, you don't even need to say 'New Char()', since VB knows that {""""c} is a char array:现在在 VB 中,您甚至不需要说 'New Char()',因为 VB 知道 {""""c} 是一个字符数组:
Dim phrases() As String = text.Split({""""c}, StringSplitOptions.RemoveEmptyEntries)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.