Practical C# 4: Getters and setters get faster with .net 3.5

I used to write basic class property implementations this way. This was boring and repetitive.

 

Style 1:

public class CaseDetails

{

   

    public CaseDetails()

    { }

 

    private string _impact = "";

    private string _capacity = "";

 

    public string impact

    {

        get

        {

            return _impact;

        }

 

        set

        {

            _impact = value;

        }

    }

    public string capacity

    {

        get

        {

            return _capacity;

        }

 

        set

        {

            _capacity = value;

        }

 

    }

}

 

 

 

which is also equal to programming it rather this way (and much faster)

 

 Style 2:

public class CaseDetails

{

   

    public CaseDetails()

    { }

 

    public string impact { get; set; }

    public string capacity { get; set; }

 

}

 

The caveat is this writing style 1 only worked on .net 2.0 framework, moving to .net 3.5 enabled the developer to write in style 2 which cut costs on development time.

 

Getters and setters get faster. Say that 10 more times.

 

Published 06-20-2009 10:17 AM by avcajipe
Filed under:

Comments

# re: Practical C# 3: Getters and setters get faster with .net 3.5

Saturday, June 27, 2009 11:07 AM by jakelite

indeed it became less verbose and more wrist-friendly with the addition of automatic properties. one tip though, you can always do 'prop' then press TAB in VS 2005/2008 to achieve either.

# re: Practical C# 3: Getters and setters get faster with .net 3.5

Monday, June 29, 2009 7:32 AM by avcajipe

oh yeah, 'prop' + <tab><tab> nice.