CSDN博客

img daiping99

精通ASP.NET(基于VB.NET)( 二)VB.NET类

发表于2003/5/1 11:15:00  448人阅读

   

                                      精通ASP.NET(基于VB.NET)( 二)VB.NET类

           (1)类的定义
                   class class_name
                   
                   end class
             (2)类的成员
                  1.域:变量的申明区
                  2.属性:提供读(GET)、写(SET)的控制接口的数据块
                           private x as integer
                           pubilc property x()
                               get
                                return _x
                               end get
                               set
                               _x=value
                               end set
                            end property
                   3.子程序与函数(方法):
                              子程序:
                                  public sub x_read()
                                  end sub
                               函数 :
                                  function x_write()
                                  end function
              (3)继承:public class class1_name 
                                                      inherits class2_name
                             end class       
              (4)重载: overloads sub x_read(x as char)
                              overloads sub x_read(x as integer)
                              overloads function  x_write(x as char)
                              overloads function  x_write(x as integer)

              (5)构造器:若未定义构造器(new方法),系统将自动创建。
            (6)notinheritable类:若类申明为notinheritable类,该类不能被继承。
                                         notinheritable class class_name
                                         end class
              (7)命名空间(namespace):提供类或一组类的寻址
                     namespace       space _name
                          public class class1
                          end class
                          public class class2
                          end class
                     end namespace
                  引用(定义类实例):Private class_name As space_name.class1
                                                     Private class_name As space_name.class2
              (8)共享方法:
                          public class class1
                           shared function x_read(ByVal a As Integer, ByVal b As Integer)
                                  Return a + b
                           end function
                           end class
                            共享方法可不通过实例化对象而直接访问。
                                dim result as inetger
                                result=class1.x_read(10,20)
              (9)共享变量:
                            public class class1
                           public shared y as integer 
                           end class
                    共享变量在所有类的实例中都是公用.
                          

 

0 0

相关博文

我的热门文章

img
取 消
img