vb.net类构建 vbnet structure

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

public structure struc

成都创新互联成立于2013年,先为万年等服务建站,万年等地企业,进行企业商务咨询服务。为万年企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

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 如何在一个项目中创建类,并且使用他?

在任意form类或模块中都可以创建类,跟建立函数和过程一样。

示例:

public class form1

‘创建一个属于form的子类,名称为【类名】。

public class 类名

’定义类成员text

public text as string

end class

‘定义一个【类名】类的公共变量。

dim 类名1 as 类名

’定义一个过程,使用【类名】类的text成员

public sub 过程

‘实例化【类名1】

类名1=new 类名

类名1.text=“赋值”

’定义一个【新类】类的私用变量,并实例化。

dim 新类1 as new 新类

新类1.name=“一个字符串”

新类1.age=12

end sub

end class

‘’‘创建一个与form同级的类,名称为【新类】

public class 新类

public sub new()

end sub

public name as string

public age as integer

end class

在模块中使用:

public class module1

dim a as new form1.类名

end module

vb.net中创建类

不熟悉VB,如有不妥的地方请包涵!

Public Class Stack

Dim aryData() As Integer

Sub New(ByVal Num As Integer)

Dim aryData(Num) As Integer

End Sub

Function Pop() As Integer

If (aryData.Length = 0) Then

Return 0

Else

Dim a As Integer

a = aryData(aryData.Length)

aryData(aryData.Length) = Convert.ToInt32(DBNull.Value)

Return a

End If

End Function

Sub Push(ByVal n As Integer)

For Each i As Integer In aryData

If (aryData(i) = Convert.ToInt32(DBNull.Value)) Then

aryData(i) = n

End

Else

Continue For

End If

Next

End Sub

Sub PrintStack()

For Each i As Integer In aryData

If (aryData(i) = Convert.ToInt32(DBNull.Value)) Then

End

Else

Print(aryData(i))

End If

Next

End Sub

End Class


网站题目:vb.net类构建 vbnet structure
文章出自:http://lszwz.com/article/dddjjgj.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款