Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#: How to set default values of properties [duplicate]

Tags:

c#

c#-3.0

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; }
like image 994
Ricky Avatar asked Dec 29 '22 09:12

Ricky


2 Answers

You need to initialize it in all constructors.

like image 160
Oded Avatar answered Jan 13 '23 17:01

Oded


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.

like image 43
Fiona - myaccessible.website Avatar answered Jan 13 '23 17:01

Fiona - myaccessible.website