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
  • 34,377
  • 39
  • 91
  • 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,481
  • 16
  • 82
  • 117
4

You need to initialize it in all constructors.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
2

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

Falle1234
  • 5,013
  • 1
  • 22
  • 29