Skip to content

Instantly share code, notes, and snippets.

@Keboo
Last active January 31, 2019 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Keboo/85e5a37ee7da43ef58b2b6d61054d3de to your computer and use it in GitHub Desktop.
Save Keboo/85e5a37ee7da43ef58b2b6d61054d3de to your computer and use it in GitHub Desktop.
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