Can I automatically generate get / set methods in C #?

Makes hands 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.

+5
source share
7 answers

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

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

(Now you do not need your fields, the compiler generates fields for creation.) Unfortunately, they do not support (yet) initialization expressions, but in your example you do not need them, since this falseis the default value for boolanyway.

+15
source

> . . , , !

+15

# 3.0 :

public bool Monday { get; set; }

:

private bool _Monday;
public bool Monday
{
    get { return _Monday; }
    set { _Monday = value; }
}
+6

Ctrl + K, Ctrl + X . "prop" . . Enter, .

+5

Visual Studio (ReSharper - ).

0

We use code snippets that allow us to provide the data type and property name on the fly. We also have the opportunity to provide the OnPropertyChanged event.

0
source

if you are using visual studio, just type prop, then click the tab, and visual studio will let you choose the type and name of the property

0
source

All Articles