原文发布时间为: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 "未知水果";
}
}
}