i'm going build mvc web application , created data models.
found online many ways compile data model code. easiest one, using public properties:
public class person { public int id { get; set; } public string firstname { get; set; } public string lastname { get; set; } }
but found version using private variable , public properies, this:
public class person { private int id; private string firstname; private string lastname; public int id { { return id; } set { id = value; } } public string firstname { { return firstname; } set { firstname = value; } } public string lastname { { return lastname; } set { lastname = value; } } }
what difference between these 2 data models? when more advisable using first 1 or second one?
this same asking: difference bwteen auto properties , normal properties.
auto properties:
- easy creation (less type)
- internal field generated automatically compiler
- not possible debug (set break point inside property)
normal properties
- sligtly more code type
- easy debug
- more code can injected inside
get
,set
Comments
Post a Comment