简体   繁体   English

System.Object[] 不能转换为 System.String[]

[英]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.

相关问题 无法将类型“ System.String”强制转换为类型“ System.Object” - Unable to cast the type 'System.String' to type 'System.Object' 无法将“ System.Object []”转换为类型“ System.String []” - Cannot convert 'System.Object[]' to the type 'System.String[]' 方法未找到:'System.String System.String.Format(System.IFormatProvider, System.String, System.Object) - Method not found: 'System.String System.String.Format(System.IFormatProvider, System.String, System.Object) 找不到方法:'System.String System.String.Format(System.IFormatProvider,System.String,System.Object)' - Method not found: 'System.String System.String.Format(System.IFormatProvider, System.String, System.Object)' LINQ to Entities无法识别方法'System.Object Parse(System.Type,System.String)' - LINQ to Entities does not recognize the method 'System.Object Parse(System.Type, System.String)' 找不到方法:'无效 System.Diagnostics.Tracing.FrameworkEventSource.BeginGetResponse(System.Object,System.String)' - Method not found: 'Void System.Diagnostics.Tracing.FrameworkEventSource.BeginGetResponse(System.Object, System.String)' Firebase 数据库错误:System.Collections.Generic.Dictionary`2[System.String,System.Object] - Firebase Database Error: System.Collections.Generic.Dictionary`2[System.String,System.Object] 多维数组转换运行时错误--->无法将类型为'System.Object [,]'的对象转换为'System.String类型 - Multidimensional Array Casting Runtime Error ---> unable to cast object of type 'System.Object[,]' to type 'System.String 无法将类型为'System.Object []'的对象强制转换为'System.String []' - Unable to cast object of type 'System.Object[]' to type 'System.String[]' String []可以在其中保存System.Object吗? - Can a String[] hold System.Object inside it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM