如何在VB.NET中的结构中初始化数组的大小 [英] How to initialize a size for array in structure in VB.NET
本文介绍了如何在VB.NET中的结构中初始化数组的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个问题需要您的帮助.
我在VB6中有一些代码,如下所示:
Hello everybody,
I have a problem that need your help.
I have some code in VB6 as below:
Public Type Employ
arrName(10) as String
End Type
现在,我想在VB.NET 2010中使用它们,如下所示:
And Now I want to use them in VB.NET 2010 as following:
Public Structure Employ
Dim arrName(10) as String
End Structure
和VB.NET显示错误:
声明为结构成员的数组不能声明为初始大小"
您有什么解决方案来初始化数组arrName的大小与VB6中的相同?
请帮帮我.
在此先感谢
and VB.NET display error:
"Arrays declared as structure members cannot be declared with initial size"
do you have which Solution to initialize a size for array arrName the same in VB6
please help me.
Thanks in advance
推荐答案
此 [< ^ ]涵盖了基础知识.您的问题是您正在结构内部执行此操作.我认为,这意味着您需要做
将arrName()变暗为String
然后在使用时通过Redim设置尺寸.至少,这就是我在搜索该错误消息时找到的内容.
This[^] covers the basics. Your problem is that you''re doing it inside a struct. Which means, I believe, you need to do
Dim arrName() as String
and then set a size when you use it, with Redim. At least, that''s what I find when I google that error message.
亲爱的ngthtra,
我也认为解决方案1是正确的,希望此示例对您有帮助.
dear ngthtra,
I also think solution 1 is right, hope this example will help u.
Sub Main()
Dim emp As Employ
ReDim emp.arrName(4)
End Sub
Public Structure Employ
Dim arrName() As String
End Structure
这篇关于如何在VB.NET中的结构中初始化数组的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文