vb.net函数结构 vbnet doevent

VB.NET 里 结构(Structure)和类(Class)有什么区别?如题 谢谢了Structure是值类型,classe是引用类型Structure用栈来分配; classe用堆来分配structure的成员默认情况下是公共的,而Class的成员变量和常量默认情况下是私有的而其它成员默认情况下是公共的.这与VB6是相兼容的 。structure必须至少有一个非共享的成员变量或事件成员 , class可以完全是空的.Structure的成员不能声明成Protected; class成员可以.一个structure过程只能在它是一个Shared Sub时才能handle events而且只能通过AddHandler语句;而任何class过程都可以handle events,既可以用Handles关键字或 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从来不析构terminated因此common language runtime (CLR)从来不调用它的Finalize方法,classe由垃圾回收器进行析构, 当没有任何对该类的引用时调用它的Finalize方法structure 不需要一个构造函数,而Class需要Structure只能有带参数的非共享的构造函数; classes 可以有带或不带参数的构造函数. 每个Structure都有一个默认的不带参数的构造函数以对其成员进行初始化 , 你可以重新定义该函数
VB.NET 如何带参数构造函数对象或是类public structure struc
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通过参数返回一个对象 , 对象可以来源于某个数组的某个元素,也可以是其他来源 。
people也可以是类的构造方法,而shengao等是类的成员,但你的写法是错误的,构造方法必须用new实例化
在VB.net中如何取变量、结构、数组、函数的地址?当然可以的 , 需要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() '取得整形数组首地址指针
MsgBox(Marshal.ReadInt32(pi, 0)) '读回整形变量指针指向的值
MsgBox(Marshal.ReadInt32(pai, 0 * 4)) '读回数组的第一个元素
MsgBox(Marshal.ReadInt32(pai, 1 * 4)) '读回数组的第二个元素
MsgBox(Marshal.ReadInt32(pai, 2 * 4)) '读回数组的第三个元素
'-----下面是结构--------------------------
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() '取得结构首地址指针
MsgBox(Marshal.ReadInt32(pm_p, 0 * 4)) '读回结构的第一个值
MsgBox(Marshal.ReadInt32(pm_p, 1 * 4)) '读回结构的第二个值
End Sub
End Class
【vb.net函数结构 vbnet doevent】关于vb.net函数结构和vbnet doevent的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读