If you look up the docs for how assignment works you will see the explanation that a = b = c
is evaluated like a = (b = c)
. The key is this line from the docs: "The result of a simple assignment expression is the value assigned to the left operand." In this case the result of the (b = c)
expression is the value in c
which is "John". This then assigns "John" into a
.
Last active
January 31, 2019 06:55
-
-
Save Keboo/85e5a37ee7da43ef58b2b6d61054d3de to your computer and use it in GitHub Desktop.
Property brain teaser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
var person = new Person(); | |
string line = person.Name = "John"; | |
Console.WriteLine(line); | |
} | |
} | |
public class Person | |
{ | |
public string Name | |
{ | |
get => "Kevin"; | |
set { } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment