Vb.net Property Get and set values without Private variables

properties, reference, vb.net

Solution

I can't imagine that Case 2 is going to run without causing a stack-overflow exception. You are essentially making an infinite loop that is going to constantly call itself.

Case 1 would be the right way to do it.

If you are using .Net 4 you could just do this (without the further Get/Set code):

Property BillId As String

This will generate the private member variable (`_BillId`) for you.

Edit:

You could try this to raise the event:

Property BillId As String
    Get
        Return _BillIdValue
    End Get
    Set(ByVal value As String)
        If Not _BillIdValue = value Then
            _BillIdValue = value
            NotifyPropertyChanged("BillId")
        End If
    End Set
End Property

Problem

Greetins, I am programmer from some time only, I have certain doubts in fundamentals, could you please clarify on the following: Case 1: ``` Public Class BillItems Implements INotifyPropertyChanged Public Event PropertyChanged As PropertyChangedEventHandler Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged Private Sub NotifyPropertyChanged(ByVal info As String) RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info)) End Sub Private _BillIdValue As String Property BillId As String Get Return _BillIdValue End Get Set(ByVal value As String) If Not _BillIdValue = value Then _BillIdValue = value End If End Set End Property End Class ``` Case 2: ``` Public Class BillItems Implements INotifyPropertyChanged Public Event PropertyChanged As PropertyChangedEventHandler Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged Private Sub NotifyPropertyChanged(ByVal info As String) RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info)) End Sub Property BillId As String Get Return BillId End Get Set(ByVal value As String) If Not BillId = value Then BillId = value End If End Set End Property End Case ``` Does case 1 and case 2 yield same result, I mean is a private value necessarily in there?, can we use property itself to use its own value in its Set and get statements? Thank you.

Original source