.NET · C# · Expression Blend

Just Get & Set a Variable

 

Just wanted to share how I shortened the example starting on the bottom of Page 164 in the VideoData.cs file in Victory Gaudioso’s “Foundation of Expression Blend 3 with Silverlight” book.  The example is the book tells you to do the following:

namespace SLVideoPlayer01
{
    public class Video
    {   

        private string _Url= "";
        public string Url
        {
            get { return _Url; }
            set { _Url= value; }
        }

        private string _Title = "";
        public string Title
        {
            get { return _Title; }
            set { _Title = value; }
        }
        private string _ThumbnailImage = "";
        public string ThumbnailImage
        {
            get { return _ThumbnailImage; }
            set { _ThumbnailImage = value; }
        }

    }
}

 

Back in .NET 2.0 you had to  do the getting and setting like this.  Since .NET 3.0 if all you are doing and setting a variable and retrieving that value without doing extra work you can use the following code:

namespace SLVideoPlayer01
{
    public class Video
    {
        public Video()
        {
            Url = string.Empty;
        }
        public string Url { get; set; }
        public string Title { get; set; }
        public string ThumbnailImage { get; set; }

    }
}

If you need to initialize the strings you can do that with the code that follows (you can also see that above):

        public Video()
        {
            Url = string.Empty;
            Title = string.Empty;
            ThumbnailImage = string.Empty;
        }

I would like to thank Scott for this pointer. 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s