zoukankan      html  css  js  c++  java
  • Dictionary SortedList HashSet List用法

    View Code
    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Web;

    using System.Web.UI;

    using System.Web.UI.WebControls;



    public partial class _Default : System.Web.UI.Page

    {

    protected void Page_Load(object sender, EventArgs e)

    {



    #region Dictionary

    var dic
    = new Dictionary<string, string>();

    dic.Add(
    "1", "111");

    dic.Add(
    "2", "222");

    dic.Add(
    "3", "333");

    dic.Add(
    "4", "444");

    foreach (KeyValuePair<string, string> key in dic)

    {

    Response.Write(String.Format(
    "这是Dictionary value:{0}<br/>", key.Value));

    Response.Write(String.Format(
    "这是Dictionary key:{0}<br/>", key.Key));

    }



    #endregion







    #region SortedList

    var sorted
    = new SortedList<string, string>();

    sorted.Add(
    "1", "111");

    sorted.Add(
    "2", "222");

    sorted.Add(
    "3", "333");

    sorted.Add(
    "4", "444");

    sorted.Add(
    "5", "555");



    foreach (KeyValuePair<string, string> book in sorted)

    {

    Response.Write(String.Format(
    "这是SortedList values:{0}<br/>", book.Value));

    Response.Write(String.Format(
    "这是SortedList key:{0}<br/>", book.Key));

    }

    foreach (string str in sorted.Values)

    {

    Response.Write(String.Format(
    "这是SortedList values:{0}<br/>", str));

    }

    foreach (string str in sorted.Keys)

    {

    Response.Write(String.Format(
    "这是SortedList key:{0}<br/>", str));

    }

    if (sorted.ContainsKey("1"))

    {

    Response.Write(
    "SortedList 列表以存在该值1<br/>");

    }

    string isnum;

    if (sorted.TryGetValue("1", out isnum))

    {

    Response.Write(String.Format(
    "SortedList 列表以存在该值{0}<br/>", isnum));

    }

    #endregion



    var hashset
    = new HashSet<string>();

    hashset.Add(
    "1");

    if (hashset.Add("1"))

    hashset.Add(
    "1");

    if (hashset.Add("2"))

    hashset.Add(
    "2");

    foreach (var hash in hashset)

    {

    Response.Write(String.Format(
    "这是HashSet{0}<br/>", hash));

    }

    var sortedset
    = new SortedSet<string>();

    sortedset.Add(
    "1");

    if (sortedset.Add("1"))

    sortedset.Add(
    "1");

    if (sortedset.Add("2"))

    sortedset.Add(
    "2");



    foreach (var _sorted in sortedset)

    {

    Response.Write(String.Format(
    "这是SortedSet{0}<br/>", _sorted));

    }



      List
    <string> list=new List<string>;

      list.add(
    "1");

      list.add(
    "2");

      list.add(
    "3");

    foreach (string str in list)

    {

    Response.Write(String.Format(
    "这是List{0}<br/>", str ));

    }

    }



    }

      这是简单用法

  • 相关阅读:
    ios系统滚动穿透
    移动h5 开发遇到ios系统的各种问题汇总
    移动端选择时间时软键盘弹出问题
    ios系统设置-webkit-overflow-scrolling: touch导致z-index 失效 (弹窗层级设置无效)- 替代方案
    npm i 报错 npmERR! code Z_BUF_ERROR errno -5 // 后继 chromedriver.zip 相关问题报错解决
    mysql、orcale、sql server的区别
    jsp中的select选择
    sql面试
    java面试题
    struts2总结
  • 原文地址:https://www.cnblogs.com/freexiaoyu/p/2160852.html
Copyright © 2011-2022 走看看