Reputation: 2155
I just started to look at Xamarin and downloaded a prebuilt contacts sample app.
It does not compile in Visual Studio because it is full of strange syntax I never saw before, searching Google didnt fruit..
For eample, this is weird:
[JsonIgnore]
public string AddressString => string.Format(
"{0} {1} {2} {3}", Street,
!string.IsNullOrWhiteSpace(City) ? City + "," : "",
State, PostalCode);
[JsonIgnore]
public string DisplayName => ToString();
[JsonIgnore]
public string DisplayLastNameFirst => $"{LastName}, {FirstName}";
[JsonIgnore]
public string StatePostal => State + " " + PostalCode;
public override string ToString()
{
return FirstName + " " + LastName;
}
These strange lambda expressions - what are they? Why are they not "="? And the $ signs? The .NET compiler spits them all out.
This is another one:
static int MatchScore(Acquaintance c, string query)
{
return new[]
{
$"{c.FirstName} {c.LastName}",
c.Email,
c.Company,
}.Sum(label => MatchScore(label, query));
}
The compiler says { and } are expected...
What did I miss in the last 5 years???
Upvotes: 2
Views: 217
Reputation: 30883
The strange syntax that you see is C# 6 syntax. You will need to open the project in VS 2015 to compile it.
The first one with lambda expressions is Expression Bodied Members. You can rewrite the first example as
public string AddressString
{
get
{
return string.Format("{0} {1} {2} {3}",
Street, !string.IsNullOrWhiteSpace(City) ? City + "," : "",
State, PostalCode);
}
}
The second one with $ sign is string interpolation and you can replace it with string.Format
Upvotes: 10