class

面向对象

namespace Example5

public class Song {
    #region Members
    string _artistName;
    string _songTitle;
    #endregion


    #region Properties
    /// <summary>
    /// The artist name.
    /// </summary>
    public string ArtistName
    {
        get { return _artistName; }
        set { _artistName = value; }
    }

    /// <summary>
    /// The song title.
    /// </summary>
    public string SongTitle
    {
        get { return _songTitle; }
        set { _songTitle = value; }
    }
    #endregion
}

/// <summary>
/// This class is a view model of a song.
/// </summary>
public class SongViewModel : ObservableObject
{
    #region Construction
    /// <summary>
    /// Constructs the default instance of a SongViewModel
    /// </summary>
    public SongViewModel()
    {
        _song = new Song { ArtistName = "Unknown", SongTitle = "Unknown" };
    }
    #endregion

    #region Members
    Song _song;
    int _count = 0;
    #endregion

    #region Properties
    public Song Song
    {
        get
        {
            return _song;
        }
        set
        {
            _song = value;
        }
    }

    public string ArtistName
    {
        get { return Song.ArtistName; }
        set 
        {
            if (Song.ArtistName != value)
            {
                Song.ArtistName = value;
                RaisePropertyChanged("ArtistName");
            }
        }
    }

    public string SongTitle
    {
        get { return Song.SongTitle; }
        set
        {
            if (Song.SongTitle != value)
            {
                Song.SongTitle = value;
                RaisePropertyChanged("SongTitle");
            }
       }
   } 
   #endregion
}

注意 MembersProperties联系区别