Auto-implemented properties

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?=

    Auto-implemented properties

    Hi,

    I think that auto-implemented properties are a wonderful new c# 3.0 feature.

    However, anyone who knows how I can set a default value (initial value) for
    the property like in the bad old days:

    int foo = 5;
    public int Foo {get ... yada yada}

  • Gregg Walker

    #2
    Re: Auto-implemented properties

    John --
    I don't mind missing default values too much. I just don't like the
    fact that you can't make readonly automatic properties.
    You probably already know this...you can't get a "true" readonly automatic
    property as in

    public int Foo { get; }

    But you can get "same as" readonly behavior with

    public int Foo { get; private set; }

    or

    public int Foo { get; protected set; }

    And the same would apply to writeonly properties as well.
    --
    Gregg Walker


    Comment

    • Gregg Walker

      #3
      Re: Auto-implemented properties

      John --
      I would rather have real, true readonly-ness, where the property could
      only be set in the constructor (the same as a readonly variable).
      Agreed.
      >And the same would apply to writeonly properties as well.
      >
      I'm not as worried about those :)
      LOL. My sentiments as well.
      --
      Gregg Walker


      Comment

      Working...