.NET Linq获取一个集合中的一个或多个属性,赋值到新的类对象

//得到自定义的list

 var list = schoolGradeClassModelList.Select(x => new DropDownListData() { DataTextField = x.gradename, DataValueField = x.grade }).ToList();

      

//新的类

       public class DropDownListData
        {
            /// <summary>
            /// 绑定的数据名称
            /// </summary>
            public string DataTextField { get; set; }
            /// <summary>
            /// 绑定的数据值
            /// </summary>
            public object DataValueField { get; set; }
            public DropDownListData() { }
            public DropDownListData(string dataTexField, string dataValueField)
            {
                this.DataTextField = dataTexField;
                this.DataValueField = dataValueField;
            }
        }

你可能感兴趣的:(.net)