-
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属性
栏目列表
最新更新
求1000阶乘的结果末尾有多少个0
详解MyBatis延迟加载是如何实现的
IDEA 控制台中文乱码4种解决方案
SpringBoot中版本兼容性处理的实现示例
Spring的IOC解决程序耦合的实现
详解Spring多数据源如何切换
Java报错:UnsupportedOperationException in Col
使用Spring Batch实现批处理任务的详细教程
java中怎么将多个音频文件拼接合成一个
SpringBoot整合ES多个精确值查询 terms功能实
数据库审计与智能监控:从日志分析到异
SQL Server 中的数据类型隐式转换问题
SQL Server中T-SQL 数据类型转换详解
sqlserver 数据类型转换小实验
SQL Server数据类型转换方法
SQL Server 2017无法连接到服务器的问题解决
SQLServer地址搜索性能优化
Sql Server查询性能优化之不可小觑的书签查
SQL Server数据库的高性能优化经验总结
SQL SERVER性能优化综述(很好的总结,不要错
uniapp/H5 获取手机桌面壁纸 (静态壁纸)
[前端] DNS解析与优化
为什么在js中需要添加addEventListener()?
JS模块化系统
js通过Object.defineProperty() 定义和控制对象
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比