+ 2
which is the proper way to code getters and setter on c#
public int getX(){ return x; } Or public int X {set => x = value; get => return x;}
3 Antworten
+ 2
it's a matter of choice it doesn't really matter.
the second example is fully introduced in C# 7 ( it was limited in C# 6)
form Microsoft docs.
" Expression body definitions let you provide a member's implementation in a very concise, readable form."
so it's about readability, I guess.
+ 1
The second one. The first one is just a method it does not make X a property.
+ 1
public string Title{get;set;}