vb.net函數(shù)結(jié)構(gòu) VBNET的編程機制

VB.NET 如何帶參數(shù)構(gòu)造函數(shù)對象或是類

public structure struc

成都創(chuàng)新互聯(lián)公司主要從事網(wǎng)站設(shè)計、網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)迎江,十多年網(wǎng)站建設(shè)經(jīng)驗,價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):18982081108

public name as string

public shengao as integer

……

end structure

public items as struc()

readonly property people(argname as string) as struc

get

for each i as struc in items

if i.name=argname then reture i

next

end get

end property

struc可以用class,property可以用function,people通過參數(shù)返回一個對象,對象可以來源于某個數(shù)組的某個元素,也可以是其他來源。

people也可以是類的構(gòu)造方法,而shengao等是類的成員,但你的寫法是錯誤的,構(gòu)造方法必須用new實例化

VB.NET 里 結(jié)構(gòu)(Structure)和類(Class)有什么區(qū)別?如題 謝謝了

Structure是值類型,classe是引用類型 Structure用棧來分配; classe用堆來分配 structure的成員默認(rèn)情況下是公共的,而Class的成員變量和常量默認(rèn)情況下是私有的而其它成員默認(rèn)情況下是公共的.這與VB6是相兼容的。 structure必須至少有一個非共享的成員變量或事件成員,class可以完全是空的. Structure的成員不能聲明成Protected; class成員可以. 一個structure過程只能在它是一個Shared Sub時才能handle events而且只能通過AddHandler語句;而任何class過程都可以handle events,既可以用Handles關(guān)鍵字或 AddHandler語句。 Structure variable declarations cannot specify initializers, the New keyword, or initial sizes for arrays; class variable declarations can. Structure繼承自ValueType類,不能從其它任何類型繼承; classes可以從任何不是ValueType的類繼承 Structure不能繼承而Class可以 Structure從來不析構(gòu)terminated因此common language runtime (CLR)從來不調(diào)用它的Finalize方法,classe由垃圾回收器進行析構(gòu), 當(dāng)沒有任何對該類的引用時調(diào)用它的Finalize方法 structure 不需要一個構(gòu)造函數(shù),而Class需要 Structure只能有帶參數(shù)的非共享的構(gòu)造函數(shù); classes 可以有帶或不帶參數(shù)的構(gòu)造函數(shù). 每個Structure都有一個默認(rèn)的不帶參數(shù)的構(gòu)造函數(shù)以對其成員進行初始化,你可以重新定義該函數(shù)

在VB.net中如何取變量、結(jié)構(gòu)、數(shù)組、函數(shù)的地址?

當(dāng)然可以的,需要System.Runtime.InteropServices?命名空間中的?Marshal?類

Imports?System.Runtime.InteropServices?'這里一定要有?

Public?Class?Form1

Public?Structure?m_Point

Dim?x?As?Integer

Dim?y?As?Integer

End?Structure

Private?Sub?Button1_Click(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Button1.Click

Dim?i?As?Integer?=?50

Dim?ai()?As?Integer?=?{1,?2,?3,?4,?5}

Dim?pi?As?IntPtr?=?GCHandle.Alloc(i,?GCHandleType.Pinned).AddrOfPinnedObject()?'取得整形變量的指針?

Dim?pai?As?IntPtr?=?GCHandle.Alloc(ai,?GCHandleType.Pinned).AddrOfPinnedObject()?'取得整形數(shù)組首地址指針

MsgBox(Marshal.ReadInt32(pi,?0))?'讀回整形變量指針指向的值

MsgBox(Marshal.ReadInt32(pai,?0?*?4))?'讀回數(shù)組的第一個元素

MsgBox(Marshal.ReadInt32(pai,?1?*?4))?'讀回數(shù)組的第二個元素

MsgBox(Marshal.ReadInt32(pai,?2?*?4))?'讀回數(shù)組的第三個元素

'-----下面是結(jié)構(gòu)--------------------------

Dim?m_p?As?New?m_Point

m_p.x?=?100

m_p.y?=?50

Dim?pm_p?As?IntPtr?=?GCHandle.Alloc(m_p,?GCHandleType.Pinned).AddrOfPinnedObject()?'取得結(jié)構(gòu)首地址指針?

MsgBox(Marshal.ReadInt32(pm_p,?0?*?4))?'讀回結(jié)構(gòu)的第一個值

MsgBox(Marshal.ReadInt32(pm_p,?1?*?4))?'讀回結(jié)構(gòu)的第二個值

End?Sub

End?Class

VB.NET中的類 有構(gòu)造函數(shù)嗎? 想C#一樣 類初始化發(fā)生的

當(dāng)父類構(gòu)造函數(shù)有多個重載時,不加base

則自動匹配父類無參數(shù)的構(gòu)造函數(shù);base()關(guān)鍵字可以顯示地指定參數(shù)以匹配父類的構(gòu)造函數(shù);EG:

class

people

{

public

string

str

=

"moren";

public

people(string

s)

{

this.str

=

s;

Console.WriteLine(this.str);

}

public

people()

{

Console.WriteLine(str);

}

}

class

me

:

people

{

public

me()

{

Console.WriteLine("me子類");

}

}

class

you

:

people

{

public

you()

:

base("you子類")

{

Console.WriteLine("you子類");

}

}

static

void

Main(string[]

args)

{

string

str

=

"main";

me

me1

=

new

me();

Console.WriteLine("===============================");

you

you1

=

new

you();

Console.Read();

結(jié)果:

moren

me子類

===============================

you子類

you子類

另外,虛機團上產(chǎn)品團購,超級便宜

網(wǎng)站標(biāo)題:vb.net函數(shù)結(jié)構(gòu) VBNET的編程機制
網(wǎng)址分享:http://www.muchs.cn/article20/hphijo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站微信小程序、網(wǎng)站收錄、關(guān)鍵詞優(yōu)化、品牌網(wǎng)站設(shè)計、靜態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

手機網(wǎng)站建設(shè)