首页 > 其他 > 详细

Dictionary字典类使用范例

时间:2017-07-13 09:21:00      阅读:220      评论:0      收藏:0      [点我收藏+]

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!