字符串数组到变体数组 [英] string array to variant array

查看:123
本文介绍了字符串数组到变体数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 私有  Sub  Form1_Load( ByVal  sender  As  System。 Object  ByVal  e  As  System.EventArgs)句柄  MyBase  .Load 
Dim a() As VariantType
Dim di As DirectoryInfo(TextBox1 .Text)
Dim diar1 As FileInfo()= di.GetFiles()
Dim dra As FileInfo
Dim i As 整数
i = 0
< span class =code-keyword>对于 每个 dra diar1
a (i)= dra.FullName.ToString
i = i + 1
下一页
结束 Sub



转换字符串到变量array.in上面的代码我已经声明a为VariantType。

如何在变量数组中存储字符串数组?

解决方案

< blockquote>我不明白你为什么要这样做,但是这是如下:

 模块 Module1 
Sub Main()
' 整数。
Dim 作为 整数 = 5

' 获取VarType。
Dim 类型 As VariantType = VarType(value)

' 写字符串表示。
Console.WriteLine(type。 ToString())

' 显示GetType方法。
控制台.WriteLine(value。 GetType ()。ToString())

' 您可以根据常量检查VariantType。
如果 type = VariantType。整数 然后
Console.WriteLine( 这是一个整数!
结束 如果
结束 Sub
结束 模块



http://www.dotnetperls.com/vartype [ ^ ]


而不是字符串数组使用列表(of of T) [ ^ ]泛型类,其中表示可以访问的强类型对象列表d按索引;提供搜索,排序和操作列表的方法



  Dim 文件作为 列表(  字符串

' 内部循环
files.Add(dra.FullName)


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim a() As VariantType
            Dim di As New DirectoryInfo(TextBox1.Text)
            Dim diar1 As FileInfo() = di.GetFiles()
            Dim dra As FileInfo
            Dim i As Integer
            i = 0
            For Each dra In diar1
                a(i) = dra.FullName.ToString
                i = i + 1
            Next
     End Sub


Convert strings to variant array.in above code i have declare "a" as VariantType.
How to store array of string in variant array?

解决方案

I dont understand why you want to do this, however this is how:

Module Module1
    Sub Main()
    ' Integer.
    Dim value As Integer = 5

    ' Get VarType.
    Dim type As VariantType = VarType(value)

    ' Write string representation.
    Console.WriteLine(type.ToString())

    ' Show GetType method.
    Console.WriteLine(value.GetType().ToString())

    ' You can check the VariantType against constants.
    If type = VariantType.Integer Then
        Console.WriteLine("It's an integer!")
    End If
    End Sub
End Module


http://www.dotnetperls.com/vartype[^]


Rather than string array use List(of T)[^] generic class, which represents a strongly typed list of objects that can be accessed by index; provides methods to search, sort, and manipulate lists.

Dim files As New List(Of String)

'inside loop
files.Add(dra.FullName)


这篇关于字符串数组到变体数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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