码迷,mamicode.com
首页 > 其他好文 > 详细

Dictionary字典类使用范例

时间:2017-07-13 10:41:13      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:event   font   百度   web   system   page   res   gen   turn   

原文发布时间为: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字典类使用范例

标签:event   font   百度   web   system   page   res   gen   turn   

原文地址:http://www.cnblogs.com/handboy/p/7158354.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!