Hopes
Start Here..
C# Dictionary 終極使用方法
using
System;
using
System.Collections.Generic;
class
DictionaryDemo
{
static
void
Main(
string
[] args)
{
DictionaryDemo001();
Console.ReadLine();
DictionaryDemo002();
Console.ReadLine();
DictionaryDemo003();
Console.ReadLine();
}
/// <summary>
/// 一般用法
/// </summary>
static
void
DictionaryDemo001()
{
Dictionary<
int
,
string
> dict =
new
Dictionary<
int
,
string
>();
dict.Add(1,
"111"
);
dict.Add(2,
"222"
);
//判斷是否存在相應的key并顯示
if
(dict.ContainsKey(2))
{
Console.WriteLine(dict[2]);
}
//遍歷Keys
foreach
(var item
in
dict.Keys)
{
Console.WriteLine(
"Key:{0}"
, item);
}
//遍歷Values
foreach
(var item
in
dict.Values)
{
Console.WriteLine(
"value:{0}"
, item);
}
//遍歷整個字典
foreach
(var item
in
dict)
{
Console.WriteLine(
"key:{0} value:{1}"
, item.Key, item.Value);
}
}
/// <summary>
/// 參數為其它類型
/// </summary>
static
void
DictionaryDemo002()
{
Dictionary<
string
,
string
[]> dict =
new
Dictionary<
string
,
string
[]>();
dict.Add(
"1"
,
"1,11,111"
.Split(
','
));
dict.Add(
"2"
,
"2,22,222"
.Split(
','
));
Console.WriteLine(dict[
"2"
][2]);
}
/// <summary>
/// 調用自定義類
/// </summary>
static
void
DictionaryDemo003()
{
Dictionary<
int
, yongfa365> dict =
new
Dictionary<
int
, yongfa365>();
for
(
int
i = 0; i < 10; i++)
{
yongfa365 y =
new
yongfa365();
y.UserCode = i;
y.UserName =
"www.yongfa365.com "
+ i.ToString();
dict.Add(i, y);
}
foreach
(var item
in
dict)
{
Console.WriteLine(
"{0} One:{1} UserName:{2}"
, item.Key, item.Value.UserCode, item.Value.UserName);
}
}
}
class
yongfa365
{
public
int
UserCode {
get
;
set
; }
public
string
UserName {
get
;
set
; }
}
posted on 2012-08-02 17:01
**
閱讀(271)
評論(0)
編輯
收藏
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
導航
BlogJava
首頁
新隨筆
聯系
聚合
管理
統計
隨筆 - 36
文章 - 294
評論 - 39
引用 - 0
公告
你好!
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(2)
給我留言
查看公開留言
查看私人留言
隨筆檔案
2014年10月 (1)
2014年7月 (2)
2014年6月 (1)
2014年5月 (1)
2014年4月 (2)
2014年3月 (2)
2014年2月 (1)
2013年12月 (2)
2013年10月 (1)
2013年9月 (1)
2013年8月 (1)
2013年6月 (1)
2012年11月 (2)
2012年10月 (3)
2012年9月 (4)
2012年8月 (3)
2012年7月 (1)
2012年5月 (4)
2012年4月 (3)
文章分類
ArcGIS
(rss)
C/C++(1)
(rss)
Matlab(2)
(rss)
文章檔案
2014年8月 (1)
2014年3月 (1)
2014年1月 (5)
2013年12月 (5)
2013年11月 (9)
2013年10月 (2)
2013年9月 (9)
2013年2月 (1)
2013年1月 (8)
2012年12月 (15)
2012年11月 (24)
2012年10月 (26)
2012年9月 (52)
2012年8月 (49)
2012年7月 (30)
2012年6月 (9)
2012年5月 (38)
2012年4月 (4)
2012年3月 (6)
新聞檔案
2013年7月 (1)
2012年10月 (1)
2012年8月 (1)
相冊
2011
收藏夾
外套(3)
(rss)
C#學習
C++操作符重載
http://www.cnblogs.com/qiantuwuliang/category/178878.html
javascript 如何用POST方式(以及Get方式) 向服務器端提交數據
不使用 Cookie 的 ASP.NET 會話管理:風險與利益
專注于Windows編程白話經典算法系列之七 堆與堆排序
十九個國內外主流的三維GIS軟件
地理坐標系與大地坐標系的差異
開發和使用Web用戶控件
手把手教您安裝和配置ArcGIS Server
掌握 ASP.NET 之路:自定義實體類簡介
白話經典算法系列之六 快速排序 快速搞定
聚簇索引(Clustered Index)和非聚簇索引 (Non- Clustered Index)舉例說明
討債公司
雷達衛星數據產品介紹
友情鏈接
搬家公司
搜索
最新評論
1.?re: Ctrl+0恢復縮放。。
恢復縮放
--張元明
2.?re: Ctrl+0恢復縮放。。
恢復縮放
--潘久新
3.?re: Ctrl+0恢復縮放。。
feichangganxie
--shanghuaiming
4.?re: 數據庫字典表設計
asdasdas
--dsfasf
5.?re: http://www.zhongguosou.com/computer_question_tools/test_regex.aspx
評論內容較長,點擊標題查看
--李丹
閱讀排行榜
1.?CAD中DWG格式轉換成SHP文件的方法(1852)
2.?矢量地圖縮放、旋轉、平移操作的實現原理(1560)
3.?中華人民共和國30米精度高程圖——效果圖(1236)
4.?呂紫劍118歲。。養生之道。。。(1061)
5.?用線性插值算法實現圖像縮放(875)
評論排行榜
1.?大學生創業政策(1)
2.?辭職后住房公積金能取出來嗎?(0)
3.?心肺復蘇(0)
4.?中華人民共和國30米精度高程圖——效果圖(0)
5.?GDEM下載(0)
Powered by:
BlogJava
Copyright © **
主站蜘蛛池模板:
肇州县
|
无极县
|
阳山县
|
娱乐
|
扎赉特旗
|
昌都县
|
调兵山市
|
肥西县
|
高密市
|
巴南区
|
东兴市
|
大理市
|
双江
|
凯里市
|
舟曲县
|
平凉市
|
通渭县
|
延安市
|
平江县
|
石台县
|
隆尧县
|
南江县
|
井冈山市
|
稷山县
|
峨眉山市
|
凤山县
|
天气
|
南召县
|
凌海市
|
浮山县
|
佛山市
|
若羌县
|
丽水市
|
墨江
|
德安县
|
湖北省
|
东乡族自治县
|
黄龙县
|
马尔康县
|
基隆市
|
平凉市
|