原文发布时间为:2009-11-04 —— 来源于本人的百度文章 [由搬家工具导入]

using System;
using System.Web.UI.WebControls;
using System.Collections.Generic;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Content content = new Content();
        Response.Write(content.Fruit(2));
        Response.Write("<br/>");
        Response.Write(content.Fruit(4));
    }
}

public class Content
{
    private Dictionary<int, string> fruit = new Dictionary<int, string>();
    public Content()
    {
        this.fruit.Add(1, "香蕉");
        this.fruit.Add(2, "苹果");
    }

    public string Fruit(int key)
    {
        if (fruit.ContainsKey(key))
        {
            return fruit[key];
        }
        else
        {
            return "未知水果";
        }
    }
}

Dictionary字典类使用范例的更多相关文章

  1. C#中的Dictionary字典类介绍

      Dictionary字典类介绍 必须包含名空间System.Collection.Generic    Dictionary里面的每一个元素都是一个键值对(由二个元素组成:键和值)    键必须是 ...

  2. (转)C#中的Dictionary字典类介绍

    关键字:C# Dictionary 字典 作者:txw1958原文:http://www.cnblogs.com/txw1958/archive/2012/11/07/csharp-dictionar ...

  3. C# Dictionary字典类介绍

    说明    必须包含名空间System.Collection.Generic     Dictionary里面的每一个元素都是一个键值对(由二个元素组成:键和值)     键必须是唯一的,而值不需要唯 ...

  4. .net中的Dictionary字典类的使用方法

    //定义字典 Dictionary<string, string> d = new Dictionary<string, string>(); //添加字典的元素 ; i &l ...

  5. c# Dictionary字典类如何使用

    Dictionary<string, string> openWith = new Dictionary<string, string>(); //添加元素 openWith. ...

  6. Dictionary字典类介绍

    说明     必须包含名空间System.Collection.Generic      Dictionary里面的每一个元素都是一个键值对(由二个元素组成:键和值)      键必须是唯一的,而值不 ...

  7. C#中的Dictionary字典类常用方法介绍

    using System.Collections.Generic;//引用命名空间//Dictionary可以理解为散列集合 public class DictionaryTest { public ...

  8. C# Dictionary 字典

    C#中的Dictionary字典类介绍   关键字:C# Dictionary 字典 作者:txw1958原文:http://www.cnblogs.com/txw1958/archive/2012/ ...

  9. Swift字典类

    在Foundation框架中提供一种字典集合,它是由“键-值”对构成的集合.键集合不能重复,值集合没有特殊要求.键和值集合中的元素可以是任何对象,但是不能是nil.Foundation框架字典类也分为 ...

随机推荐

  1. linux通配符知识

    注意:linux通配符和三剑客(grep,awk,sed)正则表达式是不一样的,因此,代表的意义也是有较大区别的. 通配符一般用户命令行bash环境,而linux正则表达式用于grep,sed,awk ...

  2. 异步解决方案----Promise与Await

    前言 异步编程模式在前端开发过程中,显得越来越重要.从最开始的XHR到封装后的Ajax都在试图解决异步编程过程中的问题.随着ES6新标准的到来,处理异步数据流又有了新的方案.我们都知道,在传统的aja ...

  3. django实现事务

    1.导入模块 from django.db import transaction 2.使用方法 with transaction.atomic(): User.objects.create(name= ...

  4. CDOJ:1636-梦后楼台高锁,酒醒帘幕低垂(Kruskal+暴力)

    梦后楼台高锁,酒醒帘幕低垂 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit ...

  5. 动态规划:HDU1864-最大报销额(处理带小数的dp问题)

    最大报销额 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Descriptio ...

  6. [BZOJ1503]郁闷的出纳员(Splay)

    Description OIER公司是一家大型专业化软件公司,有着数以万计的员工.作为一名出纳员,我的任务之一便是统计每位员工的工资.这本来是一份不错的工作,但是令人郁闷的是,我们的老板反复无常,经常 ...

  7. #3 working with data stored in files && securing your application (PART II)

    Security problems is more and more important on the internet today. You can see the problems . This ...

  8. Python及其常用模块库下载及安装

    一.Python下载:https://www.python.org/downloads/ 二.Python模块下载:http://www.lfd.uci.edu/~gohlke/pythonlibs/ ...

  9. 【POI 2010】反对称 Antisymmetry

    题目: 对于一个 $0/1$ 字符串,如果将这个字符串 $0$ 和 $1$ 取反后,再将整个串反过来和原串一样,就称作「反对称」字符串.比如 $00001111$ 和 $010101$ 就是反对称的, ...

  10. Python3.0-3.6的版本变化

    Table of Contents Python3.0 简单的变化 语法的变化 新语法 改动的语法 剩下的变化 Python3.1 Python3.2 Python3.3 Python3.4 Pyth ...