Hi I'm not an expert in C# and I found this piece of code and don't really understand what it does.
I never saw the operator =>
in c# before. Is like a redirect?
public byte[] methodA(byte[] data) =>
this.methodB(data);
Hi I'm not an expert in C# and I found this piece of code and don't really understand what it does.
I never saw the operator =>
in c# before. Is like a redirect?
public byte[] methodA(byte[] data) =>
this.methodB(data);
That's called an expression bodied method. It's new in C# 6.0.
It's equivalent to:
public byte[] methodA(byte[] data) {
return this.methodB(data);
}
It's a new feature named "Expression Bodied function" in C#6.0 which reduces your lines of code as well. e.g
//Old way
public string Name
{
get
{
return "David";
}
}
//New way
public string Name => "David";
//old way
public Address GetAddressByCustomerId(int customerId)
{
return AddressRepository.GetAddressByCustomerId(customerId);
}
//New Way
public Address GetAddressByCustomerId(int customerId) =>
AddressRepository.GetAddressByCustomerId(customerId);