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();
    
  • 相关阅读:
    为Ubuntu配置远程X访问(XDMCP & Xming)
    javascript definite guide 笔记
    marvell 88f6282 uboot编译
    qt下的跨目录多工程编译
    15 Remote Desktop Solutions for Linux.
    ubuntu中设置synergy自动开机启动
    UML 基础: 组件图
    UML基础: 统一建模语言简介
    绘制整洁的 UML 图
    养成良好的绘制 UML 序列图的习惯
  • 原文地址:https://www.cnblogs.com/sntetwt/p/3512071.html
Copyright © 2011-2022 走看看