4

Possible Duplicate:
How do you give a C# Auto-Property a default value?

Hi all:

If I want to add default value, says 60, to following property for a class, what is the most convenient way in C#3.0

public int someSetting { get; set; }
Community
  • 1
  • 1
Ricky
  • 32,609
  • 37
  • 88
  • 131
  • duplicate of at least http://stackoverflow.com/questions/3071359/set-a-default-value-to-a-property , http://stackoverflow.com/questions/40730/how-do-you-give-a-c-auto-property-a-default-value and probably many others – devio Aug 09 '10 at 07:49

3 Answers3

4

Put it in the parameterless constructor, that's what I'd do.

Edit: Yes, I guess what I mean by the above is any constructor where the parameter in question is not passed in.

Fiona - myaccessible.website
  • 14,071
  • 15
  • 78
  • 115
4

You need to initialize it in all constructors.

Oded
  • 477,625
  • 97
  • 867
  • 998
2

I would think the best way is to set the default in the constructor of the class

Falle1234
  • 4,915
  • 1
  • 21
  • 29