asp.net集合类
2024-09-21 19:00:20
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");
最新文章
- linux基础知识与技能2
- tyvj1294 小v的舞会
- webkitTransitionEnd webkitAnimationEnd事件
- The Number Off of FFF
- sublime text下代码太长brackethighlighter不能正确显示闭合高亮的解决方法
- 替换APK中的jar包文件
- struct stat 作用
- Controller 中Action 返回值类型 及其 页面跳转的用法
- 折腾源WRT的AC路无线路由-2
- flag.xls
- SEO学习知识
- PHP随机生成要求位数个字符(大小写字母+数字)
- protobuf 测试使用
- SSH框架下的表单重复提交
- samba基本应用24-4及示例
- jquery serialize对json的包装用法
- spring4-2-bean配置-1-依赖注入
- Centos中mount命令挂载windows7共享文件夹
- ORACLE 查看表空间
- 【UVA10561】Treblecross(SG函数)