SoFunction
Updated on 2025-03-07

Benefits of C# dynamic

dynamic can be used during reflection and json deserialization, and has achieved the effect of reducing the amount of code. Look at the code

using System;

namespace ConsoleApp2
{
  class Program
  {
    static void Main(string[] args)
    {
       t = typeof(Person);
      var obj = (t, null);
      ("Talk", , null, obj, new object[] { "hell world!" });

      dynamic obj2 = (t, null);
      ("hell world!");
    }
  }

  class Person
  {
    public void Talk(string msg)
    {
      (msg);
    }
  }
}
//Send a request      string result = (uri, url, data, headerdata);

      ("Get Sales List" + table + "data:");
      (result);
      //Deserialize the data into anonymous objects      var list = (result, new { records = new List<dynamic>() });

The above is the detailed content of the benefits of c# dynamic. For more information about c# dynamic, please follow my other related articles!