I was looking at someone's library the other day and they had this:
internal static string BaseUrl => "https://api.stripe.com/v1";
public static string Invoices => BaseUrl + "/invoices";
Isn't the => just acting like an assignment = operator? Wouldn't this be the same:
internal static string BaseUrl = "https://api.stripe.com/v1";
public static string Invoices = BaseUrl + "/invoices";
Never saw this before.
The => token is supported in two forms: as the lambda operator and as a separator of a member name and the member implementation in an expression body definition.
Which is NOT true about lambda statements? A statement lambda cannot return a value.
The lambda expressions have a very simple, precise syntax and provide flexibility to specify the datatypes for the function parameters. Its return type is a parameter -> expression body to understand the syntax, we can divide it into three parts.
Lambda expressions can be parameterless or have one or more parameters. The following code snippet illustrates a lambda expression that doesn't have any parameters. () => Console. WriteLine("This is a lambda expression without any parameter");
This is a new feature in C# 6.0 called Expression-Bodied, is a syntactic sugar that allows define getter-only properties and indexers where the body of the getter is given by the expression body.
public static string Invoices => BaseUrl + "/invoices";
Is the same as:
public static string Invoices
{
get
{
return BaseUrl + "/invoices";
}
}
You can read more here.
Also you can define methods as well with this syntax:
public void PrintLine(string line) => Console.WriteLine(line);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With