怎么把dictionary类型的数据转换成int型

soy_man 2011-11-02 06:51:08
如题怎么把dictionary类型的数据转换成int型,我用convent.toint32不好用。。。
...全文
288 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hch126163 2011-11-03
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 mking0412 的回复:]

C# code

Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("111", "111");
dic.Add("222", "222");

Dictionary<stri……
[/Quote]

+++

遍历Dictionary
xiongxyt2 2011-11-03
  • 打赏
  • 举报
回复
Keys 获取包含 Dictionary 中的键的集合。
Values 获取包含 Dictionary 中的值的集合。

public void Add (
TKey key,
TValue value
)

Dictionary<string, string> openWith =
new Dictionary<string, string>();

// Add some elements to the dictionary. There are no
// duplicate keys, but some of the values are duplicates.
openWith.Add("txt", "notepad.exe");
openWith.Add("bmp", "paint.exe");
openWith.Add("dib", "paint.exe");
openWith.Add("rtf", "wordpad.exe");

// The Add method throws an exception if the new key is
// already in the dictionary.
try
{
openWith.Add("txt", "winword.exe");
}
catch (ArgumentException)
{
Console.WriteLine("An element with Key = \"txt\" already exists.");
}

soy_man 2011-11-03
  • 打赏
  • 举报
回复
可以解释下 keys 跟values属性起的作用么。。。没怎么用过Dictionary...
MKing0412 2011-11-02
  • 打赏
  • 举报
回复

Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("111", "111");
dic.Add("222", "222");

Dictionary<string, string>.Enumerator e = dic.GetEnumerator();
while (e.MoveNext())
{
int i = Convert.ToInt32(e.Current.Key);
int j = Convert.ToInt32(e.Current.Value);
}

wnyxy001 2011-11-02
  • 打赏
  • 举报
回复

Dictionary<string, string> dd = new Dictionary<string, string>();
dd.Add("1","1");
dd.Add("2","2");

foreach(string a in dd.Keys)
{
int aa=Convert.ToInt32(a);
}

foreach (string b in dd.Values)
{
int bb=Convert.ToInt32(b);
}

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧