• 排序列表


        排序列表用SortedList对象表示,用Add()方法会自动将元素插入到适当的位置以保持关键字的顺序

    /*
      Example11_8.cs illustrates the use of a SortedList
    */
    
    using System;
    using System.Collections;
    
    class Example11_8
    {
    
      public static void Main()
      {
    
        // create a SortedList object
        SortedList mySortedList = new SortedList();
    
        // add elements containing US state abbreviations and state
        // names to mySortedList using the Add() method
        mySortedList.Add("NY", "New York");
        mySortedList.Add("FL", "Florida");
        mySortedList.Add("AL", "Alabama");
        mySortedList.Add("WY", "Wyoming");
        mySortedList.Add("CA", "California");
    
        // get the state name value for "CA"
        string myState = (string) mySortedList["CA"];
        Console.WriteLine("myState = " + myState);
    
        // get the state name value at index 3 using the GetByIndex() method
        string anotherState = (string) mySortedList.GetByIndex(3);
        Console.WriteLine("anotherState = " + anotherState);
    
        // display the keys for mySortedList using the Keys property
        foreach (string myKey in mySortedList.Keys)
        {
          Console.WriteLine("myKey = " + myKey);
        }
    
        // display the values for mySortedList using the Values property
        foreach(string myValue in mySortedList.Values)
        {
          Console.WriteLine("myValue = " + myValue);
        }
    
      }
    
    }
    
  • 相关阅读:
    20162302预备作业02
    20162302预备作业01
    设计模式第二次作业
    设计模式第一次作业
    项目选题报告(团队)
    高级软件工程结对第二次作业
    高级软件工程团队第一次作业
    高级软件工程结对第一次作业
    高级软件工程第二次作业
    高级软件工程第一次作业--准备
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2039424.html
Copyright © 2020-2023  润新知