expando object dynamic property RRS feed

  • Question

  • User1080785583 posted

    I have a expando object that has name value pairs as such



    How can I make my code create dynamic variable I can use later?

    var works = item.Panel0;
    dynamic panelIndex = String.Format("Panel{0}", i);
    // should be looking for Panel0 but cannot find panelIndex
    var doesntWork = item.panelIndex;

    Wednesday, April 13, 2016 10:32 PM


  • User1080785583 posted

    I'm slow.

    var couldWork = ((IDictionary<String, Object>)item)[panelIndex];

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 13, 2016 10:44 PM