DotNet慎用Shared方法

类别:.NET开发 点击:0 评论:0 推荐:

我们先来看一段代码,可以直接CP下来在VB.Net下调试查看结果

Namespace Test

    Public Class Father
        Friend Shared _x As Integer = 1
        Public Sub New()

        End Sub
    End Class

    Public Class Child
        Inherits Father

        Public Sub New()

        End Sub


    End Class


End Namespace

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim f1 As New Father
            Dim c1 As New Child
            f1._x = 1
            MessageBox.Show("Father Class 's  Shared Attribues X Has Been Modify to:" + f1._x.ToString())
            c1._x = 123
            MessageBox.Show("Child Class 's  Shared Attribues Has Been Modify to:" + c1._x.ToString())

            MessageBox.Show("In The End Father Class 's  Shared Attribues X Has Been Modify to:" + f1._x.ToString())
        End Sub

本文地址:http://com.8s8s.com/it/it41475.htm