Option Strict On 不允许后期绑定 system.array [英] Option Strict On disallows late binding with system.array

查看:37
本文介绍了Option Strict On 不允许后期绑定 system.array的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码返回 wmi 信息(未知数组)

I have the following code which return wmi information (unknown array)

For Each objMgmt In oquery.Get()
  For Each theproperty In objMgmt.Properties
    If (TypeOf objMgmt(theproperty.Name) Is System.Array) Then
      myrow(theproperty.Name) = ConvertArray(CType(objMgmt(theproperty.Name), Array)).Trim
    end if                      
  next
next

函数 ConvertArray 将其转换为字符串值.

Function ConvertArray converts this to a string value.

Function ConvertArray(ByVal myarray As System.Array) As String
    Dim tel As Integer
    Dim res As String = ""
    If myarray.Length = 0 Then
        Return ""
    End If
    If myarray.Length = 1 Then
        res = myarray(0).ToString
    Else
        For tel = 0 To myarray.Length - 1
            If TypeOf myarray(tel) Is UInt16 Then
                res = res + "[" + CType(myarray(tel), UInt16).ToString + "] , "
            Else
                res = res + CStr(myarray(tel)) + " , "
            End If
        Next
        res = Mid(res, 1, Len(res) - 2)
    End If
    Return res
End Function

myarray(tel)" 当我打开选项显式时会出现选项严格禁止延迟绑定"问题.我该如何解决这个问题,wmi 根据查询返回整数或字符串.

"myarray(tel)" give "Option Strict On disallows late binding" problem when I turn option explicit on. How can I solve this, wmi returns integers or strings depending on the query.

推荐答案

你可以用 myarray.GetValue(0) 代替 myArray(0).即使使用 Option Strict On 这也能工作.

You can do myarray.GetValue(0) instead of myArray(0). This will work even with Option Strict On.

这篇关于Option Strict On 不允许后期绑定 system.array的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆