十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
结构体无法初始化值,你可以用类实现,或者写一个构造函数,把值传进去。
十余年专注成都网站制作,成都企业网站定制,个人网站制作服务,为大家分享网站制作知识、方案,网站设计流程、步骤,成功服务上千家企业。为您提供网站建设,网站制作,网页设计及定制高端网站建设服务,专注于成都企业网站定制,高端网页制作,对三轮搅拌车等多个方面,拥有多年的网站设计经验。
Public Structure wheelmodel
Public ID As Short
Public swapway() As Short
Public start As Short
Public Sub New(ByVal Size As UShort) 'Size就是传入的数组的大小
swapway = New Short(Size) {}
End Sub
End Structure
调用的时候:
Dim x As wheelmodel = New wheelmodel(10)
一个简单的例子:
Dim a(3) As Integer = { 0, 1, 2 }**修改**既然有界数组不能初始化,就还缺(省)界数组试试嘛:
Dim a() As Integer = { 0, 1, 2 }
类型不匹配的错误估计是你的结构体缺少构造函数造成的。在你的quality_i结构体定义里面加一个构造函数,如下所示
Public Structure quality_i
Public nub As Integer
Public nae As String
Public Sub New(ub As Integer, ae As String)nub = ubnae = aeEnd SubEnd Structure然后以如下方式初始化:
你没有将数组定义为一个新的实例:
dim
j
as
Integer
dim
a(100)
as
new
Phvalue
for
j=0
to
501
...................
struct T_ChildStruct
{
int nChildData;
string strChildData;
T_ChildStruct()
{
nChildData = 0;
strChildData = ""; // string可以不用写初始化,本身构造中就有
}
};
struct T_FatherStruct
{
int nFatherData;
string strFatherData;
T_ChildStruct arrChild[10];
T_FatherStruct()
{
nFatherData = 0;
strFatherData = "";
}
};