大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
结构体无法初始化值,你可以用类实现,或者写一个构造函数,把值传进去。
成都创新互联公司坚持“要么做到,要么别承诺”的工作理念,服务领域包括:网站设计、成都做网站、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的襄垣网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!
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)
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 = "";
}
};
把“...”替换成你要初始化的数据。一个简单的例子: 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 k() As quality_i = {