系统设计中的业务验证设计2

CallByName:函数在运行时用来获取属性,设置属性或调用方法。
例子:
Imports Microsoft.VisualBasic.CallType'该方法所在的运行库
Sub TestCallByName1()
' 设置对象的属性值
**CallByName(** TextBox1, "Text", CallType.Set, "New Text" **)**
' 获取对象的属性值
MsgBox( **CallByName(** TextBox1, "Text", CallType.Get **)** )
' 调用对象的方法
**CallByName(** TextBox1, "Hide", CallType.Method **)**
End Sub

DirectCast:关键字引入类型转换操作。其使用方法和Ctype一样
例子:
Dim Q As Object = 2.37
Dim I As Integer = CType(Q, Integer) ' 成功,原因:只要定义了表达式与类型之间的有效转换,Ctype就会成功。
Dim J As Integer = **DirectCast(** Q, Integer **)** '失败,原因: DirectCast 则要求对象变量的运行时类型与指定的类型相同。如果参数类型不匹配, DirectCast 会引发 InvalidCastException 错误
如果类型匹配,DirectCast比Ctype在运行时的性能更好。

HashTable:表示键/值对的集合,这些键/值对根据键的哈希代码进行组织,该类对内存的消耗较大。
HybridDictionary:在集合较小时,使用ListDictionary 来实现 IDictionary ,然后当集合变大时,切换到HashTable。

Published At
Categories with Web编程
Tagged with
comments powered by Disqus