• asp.net集合类


    1.返回IEnumerable类型
    protected void Page_Load(object sender, EventArgs e)
    {
        IEnumerable ie = AllGet();
        Response.Write(new JavaScriptSerializer().Serialize(ie));
    }
    public IEnumerable AllGet()
    {
        return new string[] { "Item1", "Item2" }.Select(s => new
            {
                Name = s,
                Code = s,
                Items = new ArrayList
            {
            new { Name = "Item1" },
            new { Name = "Item2" },
            new { Name = "Item3" },
            new { Name = "Item4" },
        }
            });
    }
    结果:
    [{"Name":"Item1","Code":"Item1","Items":[{"Name":"Item1"},{"Name":"Item2"},{"Name":"Item3"},{"Name":"Item4"}]},
    {"Name":"Item2","Code":"Item2","Items":[{"Name":"Item1"},{"Name":"Item2"},{"Name":"Item3"},{"Name":"Item4"}]}]
    
    
    2.返回List字符串类型
    /// <summary>
    /// ["1","a","0.5"]
    /// </summary>
    /// <returns>返回List字符串类型</returns>
    public List<string> TestAjaxMethod(int a, string b, double c)
    {
        return new List<string> { a.ToString(), b, c.ToString() };
    }
    
    3.Dictionary应用
    private Dictionary<int, string> dic = new Dictionary<int, string>();
    
    4.NameValueCollection集合
    引用:using System.Collections.Specialized; 
    键是否重复,允许重复
    NameValueCollection col = new NameValueCollection();   
    col.Add("red", "rojo");//如果键值red相同结果合并 rojo,rouge
    
    //显示键,值  
    PrintKeysAndValues(col);  
    
    //按索引或值获取  
    col[1];//索引1的值  
    col["red"]);//键为red的对应值rojo
    
    //查找red键值然后删除  
    col.Remove("red");   
    
    for (int i = 0; i < col.Count; i++)  
    //清空集合  
    col.Clear();
    
    //显示索引, 键,值  
    col.GetKey(i)
    col.Get(i)
    
    foreach (string key in col.Keys)   
    col[key]
    
    5.Hashtable集合
    Hashtable与NameValueCollection相似;
    HashTable是键-值集合,但键不能出现重复.
    
    Hashtable ht = new Hashtable();  
    ht.Add("key","value");
    
  • 相关阅读:
    安装LR11 时,安装Microsoft Visual c++2005 sp1运行时组件,就会提示命令行选项语法错误,键入“命令/?”可获取帮肋信息
    用jmeter监控服务器资源
    CSS获取兄弟节点
    selenium之CSS定位
    Linux find 命令详解
    git 添加文件的可执行权限
    判断三角形类型
    冒泡排序
    selenium 显示等待 隐式等待 和强制等待
    flask 基本配置和参数解释
  • 原文地址:https://www.cnblogs.com/sntetwt/p/3503764.html
Copyright © 2020-2023  润新知