zoukankan      html  css  js  c++  java
  • .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();
    }

    }

  • 相关阅读:
    辅助方法、模型、视图数据
    HTML.Label
    HTML辅助方法
    ViewBag与ViewData
    ASP.NET MVC4 View 指定视图
    ASP.NET MVC4 配置逻辑
    大部分基于MVC的Web框架所使用的一些基本原则
    MVC内置的验证属性
    高德地图多点标记自定义地图
    关于数组的去重
  • 原文地址:https://www.cnblogs.com/yanranziruo/p/12418431.html
Copyright © 2011-2022 走看看