Skip to content

Instantly share code, notes, and snippets.

@Keboo
Last active Jan 31, 2019
Embed
What would you like to do?
Property brain teaser

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.

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