none
getting value of dynamic variable RRS feed

  • Question

  • hello, I am getting a problem while reteriving a value from dynamic variable

    I have a dynamic variable of type Class it is having Properties like Name,Age etc

     so how to get the value  dynamic d= classObject

    d.Age while Accessing these line I am getting Error

     

    Monday, March 4, 2019 10:35 AM

All replies

  • The next example works:

    class MyClass

    {

        public int Age { get; set; }

    }

     

    . . .

     

    var c = new MyClass();

    c.Age = 101;

     

    dynamic d = c;

    int age = d.Age;

     

    Console.WriteLine( age );

     

     

    Also add a reference to “Microsoft.CSharp”.

    Show your errors.

     

    Monday, March 4, 2019 5:44 PM