如何使列表指向字典值 [英] How to have List point to Dictionary values

查看:50
本文介绍了如何使列表指向字典值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Dictionary< string,myobject> myDic和List< myobject> myList我想让myList指向myDic中的值.我该怎么办?我正在使用C#4.0

预先感谢,
-DA

I have a Dictionary<string,myobject> myDic and a List<myobject> myList I''d like to have my myList point towards the values in myDic. How do I go about this? I''m using C# 4.0

Thanks in advance,
-DA

推荐答案

List<myobject> myList = new List<myobject>(myDic.Values);</myobject></myobject>



除非myobject是值类型(结构),否则它将把这些项目复制到列表中.如果真是这样,除非您开始使用指针,否则确实没有一种在两个地方引用同一对象的简便方法.



Unless myobject is a value type (struct), then it would copy the items into the list. If that''s the case, there really isn''t an easy way to reference the same object in two places unless you start using pointers...


这篇关于如何使列表指向字典值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆