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

    }

    }



    }

      这是简单用法

  • 相关阅读:
    文件工具类之FileUtils
    JAVA8日期工具类
    mybatis模糊查询匹配汉字查询不出来数据,匹配字符和数字却可以的问题解决
    问到ConcurrentHashMap不要再提Segment了
    开发中常用工具
    Spring 如何解决循环依赖?
    JVM8基础概念总结
    String字符串相等判断
    面试再也不怕问到HashMap(二)
    面试再也不怕问到HashMap(一)
  • 原文地址:https://www.cnblogs.com/freexiaoyu/p/2160852.html
Copyright © 2011-2022 走看看