VB.NET中启用Option Strict On时,如何避免与System.Array进行后期绑定?
- 内容介绍
- 文章标签
- 相关推荐
本文共计257个文字,预计阅读时间需要2分钟。
我有一段代码用于遍历返回的WMI信息(未知数组)+ 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), System.Array)) + End If + Next theproperty + Next objMgmt
我有以下代码返回wmi信息(未知数组)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(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)”给出“Option Strict On禁止后期绑定”问题.
我如何解决这个问题,wmi会根据查询返回整数或字符串.
本文共计257个文字,预计阅读时间需要2分钟。
我有一段代码用于遍历返回的WMI信息(未知数组)+ 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), System.Array)) + End If + Next theproperty + Next objMgmt
我有以下代码返回wmi信息(未知数组)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(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)”给出“Option Strict On禁止后期绑定”问题.
我如何解决这个问题,wmi会根据查询返回整数或字符串.

