AutoCAD.Net/C#.Net QQ群:193522571 LinQ 已知字段名的字符串如何从一个表中取得这个字符串对应字段的所有记录

代码如下:

其中cbFace.Text为字段名,TableFace为表名

var PnFace = (from n in TableFace
                          select n.GetType().GetProperty(cbFace.Text).GetValue(n, null));

 如果需要将获取的结果进行强制转换可以在select后的字段前加上转换语句

            var PnFace = (from n in TableFace
                          select (double)n.GetType().GetProperty(cbFace.Text).GetValue(n, null)).ToList();
原文地址:https://www.cnblogs.com/swtool/p/4028525.html