Home   Wordpress   Log in

.NET Auto-Property

March 26th, 2009 by admin | Filed under .NET.

How many times in a .NET classes have you written public properties like this?

class Testing
{
    private string m_subject;
    private string m_message;

    public string Subject
    {
        get { return m_subject; }
        set { m_subject = value; }
    }

    public string Message
    {
        get { return m_message; }
        set { m_message = value; }
    }
}
 

.NET has the ability to make that section of code a lot cleaner and easier to read through the use of Auto-Properties.

class Testing
{
    public string Subject { get; set; }
    public string Message { get; set; }
}
 

You can read a little more over at Michael Sync’s blog.

One Response to “.NET Auto-Property”

  1. n8osapi | 26/03/09

    and you can even control the scope of your getters and setters too.

    class Testing
    {
    public string Id { get; private set; }
    public string Subject { get; set; }
    public string Message { get; set; }
    }

    but this doesn’t apply to VB, Yet! VB 10 will get them when we get VB 10. So it’s kinda not correct to call it “.NET Auto-Property”… it’s “C# Auto-Property”

Share Your Thoughts

Download Full Movie Online Hytrin