本篇文章为大家展示了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中静态成员有什么用,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注创新互联行业资讯频道。