您的位置:首页 > 理论基础 > 计算机网络

类的初始化操作,定义变量

2007-01-25 17:42 316 查看
Imports System.Web.Mail

Partial Class _Default
    Inherits System.Web.UI.Page

    Public Class person
        Public Sub New()
            _eyecolor = "黑色的"
            _name = "鸿运网络科技"
        End Sub
        Private _name As String
        Private _age As Integer
        Private _eyecolor As String
        Public Property name() As String
            Get
                Return _name
            End Get
            Set(ByVal value As String)
                _name = value
            End Set
        End Property
        Public Property age() As String
            Get
                Return _age
            End Get
            Set(ByVal value As String)
                If value < 1 Then
                    value = 1
                End If
                _age = value
            End Set
        End Property

        Public ReadOnly Property eyecolor() As String
            Get
                Return _eyecolor
            End Get
        End Property
    End Class

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim myperson As New person
        myperson.age = "0"
        Label1.Text = myperson.name
        Label2.Text = myperson.age
        Label3.Text = myperson.eyecolor
    End Sub
End Class
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐