Q:

C# cascading assignment

Is there is any performance degrades when we assign values like this?
Dropdown1.Enable = dropdown2.Enable = dropdown3.Enable = false;

Thanks in advance.

A:

The answer is that there is no impact - it is equivalent to three assignment statements.
There are not even any get operations called, as is proven below:
Console application project:
using System;
using System.Diagnostics;

namespace ConsoleApplication5
{
    public class X

    {
        private int _a;
        private int _b;

        public int A
        {
            get
            {
                Console.WriteLine("get A");
                return _a + 1;
            }
            set
            {
                Console.WriteLine("set A");
                _a = value;
            }
        }

        public int B
        {
            get
            {
                Console.WriteLine("get B");
                return _b + 2;
            }
            set
            {
                Console.WriteLine("set B");
                _b = value;
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var x = new X();

            Console.WriteLine("Assign");
            int y = x.B = x.A = 125;

            Console.WriteLine("Read");
            Console.WriteLine("y " + y + " x.B " + x.B + " x.A " + x.A);

            Console.ReadLine();
        }
    }
}

Generates:
Assign
set A
set B
Read
get B
get A
y 125 x.B 127 x.A 126

Note that during the assign phase, no 'get'ers are called, and even though the getters of A and B return different values than the value set on them, the value ultimately assigned to y is the source value on the RHS of the expression.

