• .net C# SortedList用法


    // 创建一个SortedList对象
    SortedList mySL = new SortedList();
    mySL.Add("First", "Hello");

    //获得指定索引处的键和值
    int myIndex = 3;
    Console.WriteLine("The key at index {0} is {1}.", myIndex, mySL1.GetKey(myIndex));
    Console.WriteLine("The value at index {0} is {1}.", myIndex, mySL1.GetByIndex(myIndex));

    IList myKeyList = mySL1.GetKeyList();
    IList myValueList = mySL1.GetValueList();

    for (int i = 0; i < mySL1.Count; i++)
    Console.WriteLine(" {0} {1}", myKeyList[i], myValueList[i]);

    // 获得指定键的索引
    int myKey = 2;
    Console.WriteLine("The key "{0}" is at index {1}.", myKey, mySL2.IndexOfKey(myKey));

    // 获得指定值的索引
    String myValue = "three";
    Console.WriteLine("The value "{0}" is at index {1}.", myValue, mySL2.IndexOfValue(myValue));

    // 重新设置指定索引处的值
    mySL2.SetByIndex(3, "III");
    mySL2.SetByIndex(4, "IV");

    //打印SortedList中的键和值
    public static void PrintIndexAndKeysAndValues(SortedList myList)
    {
    Console.WriteLine(" -INDEX- -KEY- -VALUE-");
    for (int i = 0; i < myList.Count; i++)
    {
    Console.WriteLine(" [{0}]: {1} {2}", i, myList.GetKey(i), myList.GetByIndex(i));
    }
    Console.WriteLine();
    }

    }

  • 相关阅读:
    SQL 高级语法 (一)
    SQL 基础语法
    Memcache数据备份和还原
    OSPF原理及配置
    kubernetes全栈监控部署
    非容器化Jenkins连接Kubernetes
    Jenkins+Ansible安装部署
    Gitlab+Nexus Maven部署
    部署docker私有仓库Harbor
    LVS实现Kubernetes集群高可用
  • 原文地址:https://www.cnblogs.com/yanranziruo/p/12418431.html
Copyright © 2020-2023  润新知