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

    }

    }



    }

      这是简单用法

  • 相关阅读:
    node异步转同步(循环)
    三级省市区PCASClass.js插件
    微信公众号基础总结(待更新)
    ES6详解
    webpack配置
    高性能 CSS3 动画
    github上传口令
    纯css3 实现3D轮播图
    优美的js代码,拿去玩~
    关于列举属性用点还是用【】
  • 原文地址:https://www.cnblogs.com/freexiaoyu/p/2160852.html
Copyright © 2020-2023  润新知