-
VB.net学习笔记(六)VB.net的对象
Dim a As theClass '1,用两语句来创建实例,先声明再实例化
a = New theClass()
Dim b As New theClass() '2,仅一个语句实例化
Dim c As theClass = New theClass() '3,仅用一个语句实例化,更能表明类型与创建,在接口/继承上更好用
doSomeThing(New theClass()) ' 4,参数中创建实例
doSomeThing(New theClass().getValue()) '5,参数中创建的同时调用其方法
Public Class People
Private mName As String '字段,即数据成员
Private mBirthday As Date
End Class
Public Function Age() As Int32
Return CInt(DateDiff(DateInterval.Year, mBirthday, Now())) '用return返回值
End Function
Public Function Age() As Int32
Age = CInt(DateDiff(DateInterval.Year, mBirthday, Now())) '用方法名取得返回值
End Function
Public Class People
Private mName As String '字段,即数据成员
Private mBirthday As Date
Private mTotalDistance As Int32
Public Sub Walk(ByVal distance As Int32) '若需改变外部distance值,这里可改byval为byref
mTotalDistance += distance
End Sub
Public Function Age() As Int32
Return CInt(DateDiff(DateInterval.Year, mBirthday, Now())) '用return返回值
End Function
End Class
Public Property mName() As String
Get
Return mName
End Get
Set(value As String)
mName = value
End Set
End Property
Public Property mName() As String
Public Property Name As String
Public Property Owner As String = "DefaultName"
Public Property Items As New List(Of String) From {"M", "T", "W"}
Public Property ID As New Guid()
Public Property mName() As String
Get
Return mName
End Get
Friend Set(value As String) '仅限于项目内使用
mName = value
End Set
End Property
Private mPhones As New Hashtable '哈希表类(集合)
Public Property Phone(ByVal location As String) As String '参数类似索引在哈希表中定位
Get
Return mPhones.Item(location)
End Get
Set(value As String)
If mPhones.ContainsKey(location) Then '判断是否已经有此索引
mPhones.Item(location) = value '有,直接更新值
Else
mPhones.Add(location, value) '无,加入索引及值
End If
End Set
End Property
Private mPhones As New Hashtable
Default Public Property Phone(ByVal location As String) As String '用default表示这个属性当作对象的默认值
Get
Return mPhones.Item(location)
End Get
Set(value As String)
If mPhones.ContainsKey(location) Then
mPhones.Item(location) = value
Else
mPhones.Add(location, value)
End If
End Set
End Property
'================================================================================
Dim myPerson As New People
myPerson.Phone("home")="12345678" '没有指定为默认属性时,必须这样明确指明属性
myPerson("home")="12345678" '一旦指明默认属性为phone时,可简化成此句,自动知道是Phone属性
栏目列表
最新更新
python爬虫及其可视化
使用python爬取豆瓣电影短评评论内容
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
SQL SERVER中递归
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
uniapp/H5 获取手机桌面壁纸 (静态壁纸)
[前端] DNS解析与优化
为什么在js中需要添加addEventListener()?
JS模块化系统
js通过Object.defineProperty() 定义和控制对象
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比