一个基础问题,帮忙解答

liduoduo 2012-03-13 01:11:02
Dictionary<string, 实体> dic = new Dictionary<string, 实体>();

请问这个实体是如何定义的,请给出例子及如何调用,谢谢。不好意思,基础没学好
...全文
77 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
shizhu820228 2012-03-13
  • 打赏
  • 举报
回复
//定义:
class Entity
{
//
}
Dictionary<string, Entity> dic = new Dictionary<string, Entity>();

//填加:
dic.Add("key",entity);
//使用:
if(dic.ContainsKey("key"))
{
//给其它赋值
T t1 = new T();
dic["key"].SetValue(t1, "value", null);
}
LOVE_GG 2012-03-13
  • 打赏
  • 举报
回复
任何数据类型都可以,包括自己定义的类型和结构体
淘淘大师 2012-03-13
  • 打赏
  • 举报
回复

class Entity
{
//
}
Dictionary<string, Entity> dic = new Dictionary<string, Entity>();

jackshenbin 2012-03-13
  • 打赏
  • 举报
回复

Dictionary<string, object> dic = new Dictionary<string, object>();
Dictionary<string, string> dic = new Dictionary<string, string>();
Dictionary<string, int> dic = new Dictionary<string, int>();
class aa
{
string bb;
int cc;
}
Dictionary<string, aa> dic = new Dictionary<string, aa>();
ViewStates 2012-03-13
  • 打赏
  • 举报
回复
class 实体
{
public string Name{get;set;}
public int Age{get;set;}
}

Dictionary<string,实体> dic...;
dic.Add("gfw",new 实体{Name="hello", Age=1});
dic["gfw"].Name="乌龟";
EnForGrass 2012-03-13
  • 打赏
  • 举报
回复
int,string ,class什么的都可以

110,571

社区成员

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

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

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