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");