泛型数据集
时间:2014-01-14 19:19:53
收藏:0
阅读:622
把表里的所有字段都装载到json列表private
string GetJson(DataTable dt){ JavaScriptSerializer serializer = new
JavaScriptSerializer(); List<Dictionary<string, object>> rows = new
List<Dictionary<string, object>>(); Dictionary<string, object> row = null; foreach (DataRow dr in
dt.Rows) { row = new
Dictionary<string, object>(); foreach (DataColumn col in
dt.Columns) { row.Add(col.ColumnName.Trim(), dr[col]); } rows.Add(row); } return
serializer.Serialize(rows);}泛型数据集private
List<string> Colours { get { List<string> o = new
List<string>(); o.Add("Red"); o.Add("Blue"); o.Add("Green"); o.Add("SkyBlue"); o.Add("LimeGreen"); return
o; } }this.RadioButtonListColour.DataSource = Colours.Select(c => new
{ value = c }).ToList();Colours.ForEach(delegate(string s) { if
(s == li.Text) { li.Attributes.Add("style", "color:"
+ s); } });Linq聚合函数序号 名称 描述1 Aggregate 从某一特定序列或集合中收集值,当聚合完成时,它将序列中返回值进行累积并返回结果。2 Average 计算一个数值序列的平均值。3 Count 计算一个特定集合中元素的个数。4 LongCount 返回一个Int64类型的值,用它来计算元素大于Int32.MaxValue的集合中元素数。5 Max 返回一个序列中最大值。6 Min 返回一个序列中最小值。7 Sum 计算集合中选定值的总和。使用泛型(Generics)List<int>作为数据源:List<int> Datas = new
List<int> {2,5,6,3,8,4,7,9};int min = Datas.Min();int max = Datas.Max();double average = Datas.Average();int count = Datas.Count;int sum = Datas.Sum(); |
原文:http://www.cnblogs.com/sntetwt/p/3512071.html
评论(0)