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
.
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