资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

vb.net函数结构 VBNET的编程机制

VB.NET 如何带参数构造函数对象或是类

public structure struc

成都创新互联公司主要从事网站设计、网站建设、网页设计、企业做网站、公司建网站等业务。立足成都服务迎江,十多年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务: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通过参数返回一个对象,对象可以来源于某个数组的某个元素,也可以是其他来源。

people也可以是类的构造方法,而shengao等是类的成员,但你的写法是错误的,构造方法必须用new实例化

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中如何取变量、结构、数组、函数的地址?

当然可以的,需要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中的类 有构造函数吗? 想C#一样 类初始化发生的

当父类构造函数有多个重载时,不加base

则自动匹配父类无参数的构造函数;base()关键字可以显示地指定参数以匹配父类的构造函数;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();

结果:

moren

me子类

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

you子类

you子类

另外,虚机团上产品团购,超级便宜


分享题目:vb.net函数结构 VBNET的编程机制
URL网址:http://cdkjz.cn/article/hphijo.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220