动画介绍:大家好今天讲 structure dim 成员名1 as 数据类型 dim 成员名2 as 数据类型 end structure这是用户自定义数据类型 optional可选参数 is对象引用比较运算符 typeof...is运算符测试对象是否为某种特定类型 not逻辑非 and逻辑与 andalso快捷逻辑与 or逻辑或 orelse快捷逻辑或 xor异或 好来看实例 例子1 Module Module1 Structure student Dim strnum As String Dim strname As String Dim strsex As String Dim dtbirthday As Date Dim score() As Single End Structure Sub Main() Dim stu1 As student Dim sngave As Single Dim intage As Integer stu1.strnum = "200507280101" stu1.strname = "潇爷" stu1.strsex = "男" stu1.dtbirthday = #9/8/1987# ReDim stu1.score(4) stu1.score(0) = 75 stu1.score(1) = 81 stu1.score(2) = 68 stu1.score(3) = 92.5 stu1.score(4) = 84 sngave = (stu1.score(0) + stu1.score(1) + stu1.score(2) + stu1.score(3) + stu1.score(4)) / 5 intage = DateDiff(DateInterval.Year, stu1.dtbirthday, Now) Console.WriteLine(stu1.strname + "今天的年龄为:{0}", intage) Console.WriteLine(stu1.strname + "平均成绩为:{0}", sngave) End Sub
End Module 例子2 Module Module1 Function add(ByVal x As Integer, Optional ByVal y As Integer = 10) As Integer add = x + y End Function Sub Main() Console.WriteLine("给可选参数传值时的运算结果:{0}", add(20, 30)) Console.WriteLine("不给可选参数传值时的运算结果:{0}", add(20)) End Sub
End Module 好了教程结束 |