我认为这个问题很清楚。我有一个 Dictionary 实例,我想像 DataGridView 实例的 DataSource 一样绑定它。其实我可以这样直接绑定:
Dictionary<string,string> d = new Dictionary<string,string>();
d.Add("1","test1");
d.Add("2","test2");
DataGridView v = new DataGridView();
v.DataSource = d;
Run Code Online (Sandbox Code Playgroud)
但没有任何结果。
我想通过LINQ查询获取一个对象列表.问题是我需要设置该对象的属性,但这些属性未在其构造函数中设置.
categories.Select(c => new { c.catId, c.catName, c.catParent })
.Where(c => c.catParent == id)
.AsEnumerable()
.Select(c => new CatInfoType())
.ToList();
Run Code Online (Sandbox Code Playgroud)
例如,在Select中我需要设置CatInfoType实例的公共属性,如Id,Name等.