-1

For instance, I want to declare properties, all of which are strings:

I tried public string p1, p2, p3 { get; set; }

Obviously this does not compile, is there an easier way than this one? :

public string p1 { get; set; }

public string p2 { get; set; }

public string p3 { get; set; }

Thanks!

mehdi lotfi
  • 11,194
  • 18
  • 82
  • 128
antonicelli
  • 333
  • 1
  • 4
  • 11
  • 4
    Kids these days. I remember when we had to write out the whole getter / setter with a backing field. It was also uphill to work, both ways. – RQDQ Sep 27 '13 at 03:18
  • 2
    If you don't like typing all of that, Visual Studio has a snippet for this. Type `prop` and hit tab. – Dave Zych Sep 27 '13 at 03:18
  • Yes I know the prop snippet, but just wanted to know if an easier way existed, thanks anyways. – antonicelli Sep 27 '13 at 03:20
  • switch to vb, but then you trade one for another. `Public Property p1 as String` ;) – ps2goat Sep 27 '13 at 03:36

1 Answers1

4

Automatic properties are already a shortcut for field backed properties, but there is no shortcut for the shortcut :-)

A possible, but stringly typed workaround is to create a single Dictionary<string,string> property that can act as a property bag that can be referenced by key (property name). It will save you some typing, but it's not a strongly typed solution :-)

TGH
  • 38,769
  • 12
  • 102
  • 135