zoukankan      html  css  js  c++  java
  • 泛型数据集

    把表里的所有字段都装载到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();
    
  • 相关阅读:
    xposed
    Python-ElasticSearch写入、更新、删除、搜索
    Python 队列(Queue)用法
    支付安全的思考
    H5微信支付、支付宝支付
    for...of为什么不能遍历Object对象
    $.ajax 请求数据
    小程序内h5页面,完成分享
    typescript2---泛型和接口案例
    typescript 语法总结
  • 原文地址:https://www.cnblogs.com/sntetwt/p/3512071.html
Copyright © 2011-2022 走看看