Code_1 ( This code is using "=>", Why both of these Code have the same result )
public class Infor<TFirst, TSecond, TThird>
{
private TFirst first;
private TSecond second;
private TThird third;
public TThird Third { get => third; set => third = value; }
public TSecond Second { get => second; set => second = value; }
public TFirst First { get => first; set => first = value; }
}
Code_2 ( This code is using "return" not "=>" )
public class Infor<TFirst, TSecond, TThird>
{
private TFirst first;
private TSecond second;
private TThird third;
public TThird Third { get { return third; } set { third = value; } }
public TSecond Second { get { return second; } set { second = value; } }
public TFrist First { get { return first; } set { first = value; } }
}
No there are no differences. Internally C# compiler converts
MyProperty { get {
orset {
syntax to compiler emitted methods with the following signatures and implementations:The very same happens for
=>
syntax which is calledexpression bodied property accessors
. Usage of=>
is a merely asyntactic sugar
which was created to simplify coding and reduce boilerplate code which has to be repetitively written.