Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I auto-generate my get/set methods in c#?

Tags:

c#

Takes -ages- by hand. Can I not just select my properties and click a button?

They look like this:

private bool _Monday = false;
private bool _Tuesday = false;
private bool _Wednesday = false;
private bool _Thursday = false;
private bool _Friday = false;
private bool _Saturday = false;
private bool _Sunday = false;

and there are LOADS of them.

like image 954
NibblyPig Avatar asked Nov 04 '09 16:11

NibblyPig


1 Answers

The current version of C# (3.0) has auto properties:

public bool Monday { get; set; }
// etc …

(You don’t need your fields now, backing fields are generated by the compiler.) Unfortunately, they do not support (yet) initialization expressions – but in your example you don’t need them since false is the default value for bools anyway.

like image 114
Konrad Rudolph Avatar answered Sep 30 '22 03:09

Konrad Rudolph