谁能解释何时使用List和Hash表.在哪种情况下使用此概念? [英] Can anyone explain when will use List and Hash table.Which scenario use this concepts?

查看:61
本文介绍了谁能解释何时使用List和Hash表.在哪种情况下使用此概念?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



任何人都可以解释何时使用List和Hash表.哪种方案使用此概念?

Hi,

Can anyone explain when will use List and Hash table.Which scenario use this concepts?

推荐答案

如果您只需要一个简单的列表,该列表将由数字访问仅索引或仅按列表中项的实际值进行索引,则您将使用列表.
Hastable允许根据键值而不是索引来找到值.
If you need to just have a simple list that will be accessed by a numerical index only or only by the actual value of the item in the list then a List is what you would use.
A Hastable allows for a Value to be found based on a keyvalue rather than an index.
List<string> values = new List<string>();

values.Add("Value1");
values.Add("Value2");
values.Add("Value3");
values.Add("Value4");
values.Add("Value5");
</string></string>


在这种情况下,可以使用索引直接访问值:(即values[2]将返回"Value3")


In this instance the values can be accessed directly by using the index:(ie. values[2] will return you "Value3")

Hashtable values = new Hashtable();

values.Add("Key1", "Value1");
values.Add("Key2", "Value2");
values.Add("Key3", "Value3");
values.Add("Key4", "Value4");
values.Add("Key5", "Value5");


在这种情况下,将改为通过键名访问值:(即values["Key3"]将返回"Value3")


In this instance the values would be accessed by keyname instead: (ie. values["Key3"] will return you "Value3")


无处.从.NET网络开始从引入泛型的2.0版本开始,这些类已过时.没有正式用[Obsolete]属性标记,只是因为支持遗留代码就可以了,但是对于所有新开发,都不应使用它们.

相反,您需要使用System.Collections.Generic.List<>:
http://msdn.microsoft.com/en-us/library/6sh2ey19%28v = vs.100%29.aspx [ ^ ].

您可以使用三个泛型类中的一个(或多个)来代替哈希表:
http://msdn.microsoft.com/en-us/library/xfhwa508%28v = vs.100%29.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/f7fta44c%28v = vs.100%29.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/ms132319%28v = vs.100%29.aspx [ ^ ].

它们之间的差异主要在于实现上,以及速度和冗余之间的权衡取舍.

另请参见:
http://en.wikipedia.org/wiki/Redundancy_%28information_theory%29 [ ^ ].

要解释或列出使用这些集合的所有情况,都是不可行的.它们是非常基础的数据结构,在大多数基础计算机科学中都是众所周知的,您应该学习.

如果该集合实际上是由其操作集和每个集合的计算复杂度信息定义的,则使用该集合.为了能够为集合选择适当的类型,您实际上需要了解集合类和集合接口的 all .对于适当的封装,维护等而言,重要的是在可能的情况下通过.NET接口访问类,而不是将引用传递给集合类以直接使用.

好吧,列表是一个具有随机访问权限的线性通用集合.考虑它是否为可变长度的数组.上面提到的其他集合是用于通过键快速访问的集合,该集合用作索引,该索引不必是数字的,也不必用连续的值填充范围.尽管如此,这是一次搜索,其计算复杂度为O(1).您还需要它来了解这种复杂性和"Big O"表示法:
http://en.wikipedia.org/wiki/Computational_complexity_theory [ http://en.wikipedia.org/wiki/Big_O_notation [ http://en.wikipedia.org/wiki/Big_O_in_probability_notation [
Nowhere. As of .NET network versions starting with 2.0, where the generics were be introduced, these classes are rendered obsolete. There were not formally marked with [Obsolete] attribute only because for supporting of legacy code they are just fine, but for all new developments they should not be used.

Instead, you need to use System.Collections.Generic.List<>:
http://msdn.microsoft.com/en-us/library/6sh2ey19%28v=vs.100%29.aspx[^].

Instead of the hash table, you can use one (or more) of three generic classes:
http://msdn.microsoft.com/en-us/library/xfhwa508%28v=vs.100%29.aspx[^],
http://msdn.microsoft.com/en-us/library/f7fta44c%28v=vs.100%29.aspx[^],
http://msdn.microsoft.com/en-us/library/ms132319%28v=vs.100%29.aspx[^].

The difference between them are mostly in implementation and different trade-off between speed and redundancy.

See also:
http://en.wikipedia.org/wiki/Redundancy_%28information_theory%29[^].

It''s not feasible to explain or list all scenarios of using these collections. They are very basic data structures well known in most elementary computer science which you should learn.

The use if the collection is actually defined by its operation set and information of the computational complexity of each. To be able to select an appropriate type for a collection, you practically need to know all of collection classes and collection interfaces. It''s important for proper encapsulation, maintenance, etc., to access classes through .NET interfaces where possible, instead of passing the references to the collection classes for direct use.

Well, list is a linear general-purpose collection with random access; think if it as of an array with variable length. The other collections mentioned above are the collection for fast access by the key, which is used as an index, which does not have to be numeric, and does not have to fill a range with consecutive values. Still, this is a search, and its computational omplexity is of O(1). What you also need it to understand this complexity and the "Big O" notation:
http://en.wikipedia.org/wiki/Computational_complexity_theory[^],
http://en.wikipedia.org/wiki/Big_O_notation[^],
http://en.wikipedia.org/wiki/Big_O_in_probability_notation[^].

—SA


关注以下链接中的讨论...
1.
列表< t> vs hashtable [ ^ ]
2. ArrayList与哈希表 [
Follow the discussions in below links...
1. List<t> vs hashtable[^]
2. ArrayList Vs Hash Table[^]


这篇关于谁能解释何时使用List和Hash表.在哪种情况下使用此概念?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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