小编Cam*_*m L的帖子

来自Getter的VB.NET Call Setter

我有一个这样的课:

Public Class MyClass

Private _intList As New List(Of Integer)
Private _avg As Decimal

Public Sub Add(ByVal anInt As Integer)
    _intList.Add(anInt)
End Sub

Public Property Avg() As Decimal
    Get
        Dim _sum As Integer = 0
        For Each anInt In _intList
            _sum += anInt
        Next
        Avg = If((_intList.Count > 0), _sum / _intList.Count, _avg)
        Return _avg
    End Get
    Set(ByVal value As Decimal)
        If _avg <> value Then
            _avg = value
            Console.WriteLine("Value changed")
        End If
    End Set
End Property

End Class
Run Code Online (Sandbox Code Playgroud)

Getter正在计算平均值并调用Setter来保存该值.由于某种原因,我无法理解,平均值始终为0.例如: …

vb.net getter setter properties

0
推荐指数
1
解决办法
2904
查看次数

标签 统计

getter ×1

properties ×1

setter ×1

vb.net ×1