-5

As int the subject

public String imie, nazwisko{get; private set;}

I would apply get/set rule for both of them imie and nazwisko in the same row

Yoda
  • 17,363
  • 67
  • 204
  • 344
  • 6
    Are you trying to define 2 properties in 1 line? If so you can't. – Daniel Kelley Jan 19 '13 at 20:54
  • 1
    You can't do that. Each property has to have its own declaration. – k.m Jan 19 '13 at 20:54
  • 1
    if I can declare many fields of the same type in one row I would like to do it here to. – Yoda Jan 19 '13 at 20:57
  • 2
    Why? What does having these in one "row" give you? – Oded Jan 19 '13 at 20:58
  • 1
    And those are **not** fields. They are **properties**. – Oded Jan 19 '13 at 20:58
  • I just explained the difference between **properties** and **fields** on http://stackoverflow.com/questions/14418612/how-getter-should-look/14418649#14418649 – atlaste Jan 19 '13 at 20:59
  • 1
    @Oded just java manner if I have ten ints in the class definition I don't want write int val; int val2; int...... ; int val10 – Yoda Jan 19 '13 at 21:00
  • Well, to be fair, you _can_ declare them in one row by skipping the line break: `public string imie {get; private set; } public string nazwisko {get; private set; }` but of course, this isn't actually what Robert is going for. :) – Chris Sinclair Jan 19 '13 at 21:00
  • 2
    @RobertKilar - You can declare fields that way. The `{get; set;}` syntax is not for fields - it is for properties. – Oded Jan 19 '13 at 21:02

1 Answers1

4

If you want to declare multiple fields in one statement, you can:

public string imie, nazwisko, whatever;

What you have posted is an attempt to do the same with properties, which is not possible (not with shared getter/setter declaration).

Though, of course these can be on one line:

public string imie{get; private set;} public string nazwisko{get; private set;}

I suggest reading about fields and properties on MSDN.

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