有序列表---SortedList<TKey,TValue>

发布时间:2020-05-27 22:59:50 作者:1473348968
来源:网络 阅读:891

==================================主程序

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            //有序列表会按照键排序
            SortedList<string, string> s = new SortedList<string, string>();
            s.Add("a", "1");
            s.Add("b", "3");
            s["d"] = "2";
            s["c"] = "4";
            Console.WriteLine("--------------【遍历有序列表】-----------------");
            foreach (var item in s)
            {
                Console.WriteLine(item.Key + "," + item.Value);
            }
            Console.WriteLine("--------------【遍历有序列表的值】-----------------");
            foreach (var item in s.Values)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("--------------【遍历有序列表的键】-----------------");
            foreach (var item in s.Keys)
            {
                Console.WriteLine(item);
            }
            
            //获取有序列表的值【安全获取】
            string outstr;//返回值
            string key = "a";//键
            if (!s.TryGetValue(key,out outstr))
            {
                Console.WriteLine(key + "键不存在");
            }
            Console.WriteLine(outstr);
            Console.ReadKey();
 

          
        }
    }
}

 

推荐阅读:
  1. HTML的ol有序列表
  2. IDictionary<TKey,TValue>数据字典使用讲解

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

列表 list sort

上一篇:layui怎样用templet格式化表格数据?

下一篇:Kubernetes中CRD的介绍和使用

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》