📜  c# 创建动态对象 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:04.291000             🧑  作者: Mango

代码示例1
// my pretend dataset
        List fields = new List();
        // my 'columns'
        fields.Add("this_thing");
        fields.Add("that_thing");
        fields.Add("the_other");

        dynamic exo = new System.Dynamic.ExpandoObject();

        foreach (string field in fields)
        {
            ((IDictionary)exo).Add(field, field + "_data");
        }

        // output - from Json.Net NuGet package
        textBox1.Text = Newtonsoft.Json.JsonConvert.SerializeObject(exo);