本文向大家介绍VB.NET静态成员,可能好多人还不了解VB.NET静态成员,没有关系,看完本文你肯定有不少收获,希望本文能教会你更多东西。
VB.NET静态成员
在面向对象编程语言中,有一种被称作静态成员的特殊的类成员,VB.NET也有静态成员这一概念。无需对一个对象实例化就可以使用其中的VB.NET静态成员。例如,下面的表中,SalaryLevel类中就只包含有静态的域:
- Class SalaryLevel
- Public Shared Level1 As Decimal = 35000
- Public Shared Level2 As Decimal = 40000
- Public Shared Level3 As Decimal = 45000
- Public Shared Level4 As Decimal = 50000
- Public Shared Level5 As Decimal = 55000
- Public Shared Level6 As Decimal = 60000
- Public Shared Level7 As Decimal = 65000
- Public Shared Level8 As Decimal = 70000
- Public Shared Level9 As Decimal = 75000
- Public Shared Level10 As Decimal = 80000
- End Class
我们可以像下表中的程序所演示的那样在程序中使用类:
- Imports System
- Class SalaryLevel
- Public Shared Level1 As Decimal = 35000
- Public Shared Level2 As Decimal = 40000
- Public Shared Level3 As Decimal = 45000
- Public Shared Level4 As Decimal = 50000
- Public Shared Level5 As Decimal = 55000
- Public Shared Level6 As Decimal = 60000
- Public Shared Level7 As Decimal = 65000
- Public Shared Level8 As Decimal = 70000
- Public Shared Level9 As Decimal = 75000
- Public Shared Level10 As Decimal = 80000
- End Class
- Class Employee
- Dim yearlyBonus As Decimal = 4000
- Public Sub PrintSalary()
- '使用SalaryLevel类的静态域向Console输出工资额
- Console.Write(SalaryLevel.Level4)
- End Sub
- Public Shared Sub Main()
- Dim employee As Employee
- employee = New Employee()
- employee.PrintSalary()
- End Sub
- End Class
在Employee类的PrintSalary方法中,我们可以在不首先创建SalaryLevel类变量的情况下使用其中的静态域Level4。不属于VB.NET静态成员的类成员被称作实例成员。
当前文章:简单讲解VB.NET静态成员
URL网址:http://www.shufengxianlan.com/qtweb/news19/456569.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联