Over a million developers have joined DZone.

Dynamic resolution rules joy

DZone 's Guide to

Dynamic resolution rules joy

· ·
Free Resource

In the following code, what do you believe the output should be?

class Program
    static void Main(string[] args)
        dynamic stupid = new Stupid{Age = 3};


public class Stupid : DynamicObject
    public int Age { get; set; }

    public override bool TryGetMember(GetMemberBinder binder, out object result)
        result = 1;
        return true;


The default is to use the actual type members, and then fall back to the dynamic behavior. Whereas I would expect it to first check the dynamic behavior and then fall back to the actual members if it can’t find dynamic stuff.

Quite annoying.


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}