Dictionary类问题

advantking 2010-09-13 09:57:25
class L_11
{
private static void Main()
{


Dictionary dict = new Dictionary();
dict.Add(1, "c++");
dict.Add(2, "C");
dict.Add(3, "Ada");
dict.Add(4, "APL");
dict.Add(5, "VB");
dict.Add(6, "C#");
dict.Add(7, "Java");
dict.Add(8, "FORTRAN");
foreach (DictionaryEntry de in dict)
{
Console.WriteLine("Entry KEY{0},VALUE{1}", de.Key,de.Value);
}
Console.ReadLine();
}
}
提示这样的错误“使用泛型 类型“System.Collections.Generic.Dictionary<TKey,TValue>”需要“2”个类型实参”
不明白什么意思,泛型要怎么理解啊,请教高手。
...全文
113 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jason成都 2010-09-13
  • 打赏
  • 举报
回复
需要2个参数使用时。
Peter200694013 2010-09-13
  • 打赏
  • 举报
回复
Dictionary<int, string> dict = new Dictionary<int, string>();
wuyq11 2010-09-13
  • 打赏
  • 举报
回复
Dictionary<int, string> dict = new Dictionary<int, string>();
dict.Add(1, "c++");
dict.Add(2, "C");
dict.Add(3, "Ada");
foreach( KeyValuePair<int,string> entry in dict)
{
Console.WriteLine(
string.Format("key:{0}\nvalues:{1}\n",
entry.Key,
entry.Value
)
);
}
  • 打赏
  • 举报
回复
泛型 就是一种事先定义好的类型,不需要你装拆箱操作

比如list<string>
Dictionary(string,List<user>)

110,536

社区成员

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

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

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