1、先定義一個結(jié)構(gòu)體
創(chuàng)新互聯(lián)公司自2013年創(chuàng)立以來,先為興平等服務(wù)建站,興平等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為興平企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
2、初始化并定義一個結(jié)構(gòu)體的變量
3、使用該變量即可
一個簡單的例子:
Dim a(3) As Integer = { 0, 1, 2 }**修改**既然有界數(shù)組不能初始化,就還缺(?。┙鐢?shù)組試試嘛:
Dim a() As Integer = { 0, 1, 2 }
類型不匹配的錯誤估計是你的結(jié)構(gòu)體缺少構(gòu)造函數(shù)造成的。在你的quality_i結(jié)構(gòu)體定義里面加一個構(gòu)造函數(shù),如下所示
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然后以如下方式初始化:
結(jié)構(gòu)體無法初始化值,你可以用類實(shí)現(xiàn),或者寫一個構(gòu)造函數(shù),把值傳進(jìn)去。
Public Structure wheelmodel
Public ID As Short
Public swapway() As Short
Public start As Short
Public Sub New(ByVal Size As UShort) 'Size就是傳入的數(shù)組的大小
swapway = New Short(Size) {}
End Sub
End Structure
調(diào)用的時候:
Dim x As wheelmodel = New wheelmodel(10)
struct T_ChildStruct
{
int nChildData;
string strChildData;
T_ChildStruct()
{
nChildData = 0;
strChildData = ""; // string可以不用寫初始化,本身構(gòu)造中就有
}
};
struct T_FatherStruct
{
int nFatherData;
string strFatherData;
T_ChildStruct arrChild[10];
T_FatherStruct()
{
nFatherData = 0;
strFatherData = "";
}
};