Dictionary字典类使用范例
原文发布时间为: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字典类使用范例的更多相关文章
- C#中的Dictionary字典类介绍
Dictionary字典类介绍 必须包含名空间System.Collection.Generic Dictionary里面的每一个元素都是一个键值对(由二个元素组成:键和值) 键必须是 ...
- (转)C#中的Dictionary字典类介绍
关键字:C# Dictionary 字典 作者:txw1958原文:http://www.cnblogs.com/txw1958/archive/2012/11/07/csharp-dictionar ...
- C# Dictionary字典类介绍
说明 必须包含名空间System.Collection.Generic Dictionary里面的每一个元素都是一个键值对(由二个元素组成:键和值) 键必须是唯一的,而值不需要唯 ...
- .net中的Dictionary字典类的使用方法
//定义字典 Dictionary<string, string> d = new Dictionary<string, string>(); //添加字典的元素 ; i &l ...
- c# Dictionary字典类如何使用
Dictionary<string, string> openWith = new Dictionary<string, string>(); //添加元素 openWith. ...
- Dictionary字典类介绍
说明 必须包含名空间System.Collection.Generic Dictionary里面的每一个元素都是一个键值对(由二个元素组成:键和值) 键必须是唯一的,而值不 ...
- C#中的Dictionary字典类常用方法介绍
using System.Collections.Generic;//引用命名空间//Dictionary可以理解为散列集合 public class DictionaryTest { public ...
- C# Dictionary 字典
C#中的Dictionary字典类介绍 关键字:C# Dictionary 字典 作者:txw1958原文:http://www.cnblogs.com/txw1958/archive/2012/ ...
- Swift字典类
在Foundation框架中提供一种字典集合,它是由“键-值”对构成的集合.键集合不能重复,值集合没有特殊要求.键和值集合中的元素可以是任何对象,但是不能是nil.Foundation框架字典类也分为 ...
随机推荐
- [BZOJ] 3301: [USACO2011 Feb] Cow Line
康拓展开/逆展开 模板 #include<algorithm> #include<iostream> #include<cstdio> #define int lo ...
- mysql 基础,列类型
- nginx修改nginx.conf配置可以https访问
修改nginx.conf,参照如下更改配置server { listen 443; server_name abc.com; // 访问域名 ssl on; root /var/www/bjubi.c ...
- 【解决】ERROR in xxx.js from UglifyJs
当我们运行打包脚本npm run build或者打包iosweexpack build ios有可能会遇到以下报错 ERROR in index.js from UglifyJs  { # comment try_files $uri =404; to enable pathinfo try_files $uri ...
- JVM 内存分配和回收策略
对象的内存分配,主要是在java堆上分配(有可能经过JIT编译后被拆为标量类型并间接地在栈上分配),如果启动了本地线程分配缓冲,将按线程优先在TLAB上分配.少数情况下也是直接分配到老年代,分配规则不 ...
- Python3爬取起点中文网阅读量信息,解决文字反爬~~~附源代码
起点中文网,在“数字”上设置了文字反爬,使用了自定义的文字文件ttf通过浏览器的“检查”显示的是“□”,但是可以在网页源代码中找到映射后的数字正则爬的是网页源代码,xpath是默认utf-8解析网页数 ...
- RGB色彩的计算机表示
计算机显示模式[编辑] 24比特模式[编辑] 每像素24位(比特s per pixel,bpp)编码的RGB值:使用三个8位无符号整数(0到255)表示红色.绿色和蓝色的强度.这是当前主流的标准表示方 ...
- [USACO]Bovine Genomics
Description 给定两个字符串集合A,B,均包含N个字符串,长度均为M,求一个最短的区间[l,r],使得不存在字符串\(a\in A,b\in B,\)且\(a[l,r]=b[l,r]\) , ...
- SSH无密码登录及远程拷贝命令SCP的使用
SSH无密码登录 1.生成密钥对(公钥和私钥) $ cd /home/cen/.ssh $ ssh-keygen -t rsa #生成密钥,使用rsa方式进行加密,四个回车 $ ssh-copy-id ...