无法将类型为“System.String[*]”的对象强制转换为类型“System.String[]”

he036002 2020-06-22 06:39:22
System.InvalidCastException: 无法将类型为“System.String
  • ”的对象强制转换为类型“System.String
  • []”

    百度不可其解。
...全文
2693 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
正怒月神 2020-06-23
  • 打赏
  • 举报
回复
引用 5 楼 he036002 的回复:
object a = image.Attributes[0x20, 0x32].Value[1];这一行报错 System.String
  • ”的对象强制转换为类型“System.String
  • [] image.Attributes[0x20, 0x32].Value,是一个数组。用其它语言能取到值,用c#遇到了困难。 System.String
  • 是什么呢
看起来像嵌套数组,没有遇到过。 其他语言能取到值,是哪个语言?
he036002 2020-06-23
  • 打赏
  • 举报
回复
object a = image.Attributes[0x20, 0x32].Value[1];这一行报错 System.String
  • ”的对象强制转换为类型“System.String
  • []
    image.Attributes[0x20, 0x32].Value,是一个数组。用其它语言能取到值,用c#遇到了困难。

    System.String
  • 是什么呢
正怒月神 2020-06-23
  • 打赏
  • 举报
回复
ImagePosY 是什么类型。 image.Attributes[0x20, 0x32].Value[2]又是什么类型
he036002 2020-06-23
  • 打赏
  • 举报
回复
我需要从DCM文件中取一些信息出来。

DicomImage image = images.ReadFile(strNewFullFilePath);

if (image.Attributes[0x20, 0x32].Exists == true)
{
try
{

object a = image.Attributes[0x20, 0x32].Value[1];
ImagePosY = image.Attributes[0x20, 0x32].Value[2];
ImagePosZ = image.Attributes[0x20, 0x32].Value[3];
}
catch (Exception e)
{

MessageBox.Show(e.ToString());
throw e;
}

}


引用 2 楼 正怒月神 的回复:
把你报错的那行代码,发出来。
正怒月神 2020-06-23
  • 打赏
  • 举报
回复
把你报错的那行代码,发出来。
he036002 2020-06-23
  • 打赏
  • 举报
回复
VB
        Dim objDicomImage As DicomImage

100 Set objDicomImage = frmMain.DicomViewer1.Images.ReadFile(strFilePath)

Dim strXYZ() As String

102 ReDim strXYZ(1)

Dim strX As String, strY As String, strZ As String

104 If objDicomImage.Attributes(&H20, &H32).Exists = True Then

106 strXYZ = objDicomImage.Attributes(&H20, &H32).Value

End If

108 If UBound(strXYZ) = 3 Then

110 GetDCMXYZByDCMFilePath = strXYZ(1) & "," & strXYZ(2) & "," & strXYZ(3)
End If
threenewbee 2020-06-22
  • 打赏
  • 举报
回复
看你的代码,类型不匹配,或者 Interop 调用的方法签名定义错误。

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧