集合与词典 [英] Collection vs Dictionary

查看:49
本文介绍了集合与词典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


这些方便的

课程之间的目的和区别存在一些混淆......

首先,他们都持有多个键值对,对吧?然后,我看到,b / b
键和值允许的数据类型可能会有所不同吗?


我在MSDN中阅读了以下有关CollectionBase的内容。 class和

" DictionaryBase"类:

CollectionBase:为强类型集合提供抽象(Visual Basic中的MustInherit)基础

类。

DictionaryBase:提供摘要(Visual Basic中的MustInherit)基础

类为一个强类型的键值对集合


嘿,这隐含地表示Collection不是* *收集

键值对,这当然不是真的。那么真相是什么?


System.Hashtable类似乎是

字典类中最灵活的代表,同时具有键和值类型"对象" ;.那个

是否意味着如果价值类型的任何一个键被固定到一个特定的,那么就更不会被称为Hastable?

- Pavils

Hello,

There''s some confusion about the purpose and difference between these handy
classes...

First, both of them are holding number of key - value pairs, right? Then, I
see that there may be some difference in terms of data types allowed for
keys and values, perhaps?

I read the following in MSDN about "CollectionBase" class and
"DictionaryBase" classes:
CollectionBase: Provides the abstract (MustInherit in Visual Basic) base
class for a strongly typed collection.
DictionaryBase: Provides the abstract (MustInherit in Visual Basic) base
class for a strongly typed collection of key-and-value pairs

Hey, this implicitly signals that Collection is *not* collection of
key-and-value pairs, which is certainly not true. Then what''s the truth?

The System.Hashtable class seems to be the most flexible representative of
Dictionary classes, having both key and value types "object". Would that
imply that if either key of value type is anchored to one specific, it is no
more to be called "Hastable"?
-- Pavils

推荐答案

Pavils Jurjans< pa **** @ mailbox.riga.lv>写道:
Pavils Jurjans <pa****@mailbox.riga.lv> wrote:
关于这些方便的课程之间的目的和区别存在一些混淆......首先,两者都持有关键数量 - 价值对,对吗?


错误。收藏品只需要是价值集合 - 不需要

键。

那么,我看到在允许的数据类型方面可能存在一些差异对于
键和值,或许?

我在MSDN中阅读了以下有关CollectionBase的内容。 class和
" DictionaryBase" classes:
CollectionBase:为强类型集合提供抽象(Visual Basic中的MustInherit)基类。
DictionaryBase:提供抽象(Visual Basic中的MustInherit)基类
类对于一个强类型的键值对的集合

嘿,这隐含地表明Collection不是*不是*键值对的集合,这当然不是真的。那真相是什么?


不,这是真的 - ICollection *不是*键/值对的集合。

它是一组值。你在哪里知道这是一个关键/值对的集合?

System.Hashtable类似乎是最灵活的代表
字典类,具有键和值类型对象。这是否意味着如果任何一个值类型的键被锚定到一个特定的键,那么就更不会被称为Hastable?
There''s some confusion about the purpose and difference between these handy
classes...

First, both of them are holding number of key - value pairs, right?
Wrong. Collections only need to be collections of values - no need for
keys.
Then, I
see that there may be some difference in terms of data types allowed for
keys and values, perhaps?

I read the following in MSDN about "CollectionBase" class and
"DictionaryBase" classes:
CollectionBase: Provides the abstract (MustInherit in Visual Basic) base
class for a strongly typed collection.
DictionaryBase: Provides the abstract (MustInherit in Visual Basic) base
class for a strongly typed collection of key-and-value pairs

Hey, this implicitly signals that Collection is *not* collection of
key-and-value pairs, which is certainly not true. Then what''s the truth?
No, it is true - ICollection is *not* a collection of key/value pairs.
It''s a collection of values. Where did you get the idea that it''s a
collection of key/value pairs?
The System.Hashtable class seems to be the most flexible representative of
Dictionary classes, having both key and value types "object". Would that
imply that if either key of value type is anchored to one specific, it is no
more to be called "Hastable"?




我没有完全遵循这句话,但你当然可以在哈希表中使用值

类型,作为键或值。他们最终得到了

盒装。


-

Jon Skeet - < sk *** @ pobox.com> ;
http://www.pobox.com/~skeet

如果回复小组,请不要给我发邮件



I didn''t quite follow that sentence, but you can certainly use value
types in hashtables, as either keys or values. They just end up getting
boxed.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Hello John,
Hello John,
不,这是真的 - ICollection *不是*键/值对的集合。
它是一组价值观。你在哪里知道这是一个关键/价值对的集合?


我对术语收集的理解来自VB,尤其是编程

之前使用经典的ASP将所有ASP开发转换为JScript对几年前的b $ b。因此,在传统的ASP中,例如,我得到一个表格的集合

变量。在Request.Form对象中。因为它们是可读的,所以提供密钥,

我的印象是收藏肯定是键值对持有

结构。所以,据我的评论看,C#集合不应该与VB集合混淆。 Soo ..有一个地方

集合中的项目,或者它就像一个东西,其中的顺序是什么?

无关紧要?我看到对集合中的第一项的引用在许多地方,

显然有某种秩序。但是,那么,有什么意义是使用

集合代替数组?
No, it is true - ICollection is *not* a collection of key/value pairs.
It''s a collection of values. Where did you get the idea that it''s a
collection of key/value pairs?
My understanding of term "collection" comes from VB, especially programming
with classic ASP prior to transerring all ASP developement to JScript couple
of years ago. So, in classic ASP, for example, I get "A collection of form
variables" in Request.Form object. Since they are readable by providing key,
I was under impression that collection certainly is key-value pair holding
structure. So, as far as I see from your comments, C# collection should not
be confused with VB collection. Soo.. is there a "place" of item within
collection, or it''s like a sack with stuff where order of thnks is
irrelevant? I see references to "first item in collection" in many places,
so obviously there is some sort of order. But then, what point is to have
collection instead of array?
System.Hashtable类似乎是最灵活的代表
of字典类,具有键和值类型对象。这是否意味着如果值类型的任一键被锚定到一个特定的,那么
不再被称为Hastable?
The System.Hashtable class seems to be the most flexible representative of Dictionary classes, having both key and value types "object". Would that
imply that if either key of value type is anchored to one specific, it is no more to be called "Hastable"?



我没有不太会遵循这句话,但你当然可以在哈希表中使用值
类型,作为键或值。他们最终得到了装箱。



I didn''t quite follow that sentence, but you can certainly use value
types in hashtables, as either keys or values. They just end up getting
boxed.




我的意思是,大部分时间我都不需要反对。关键类型,它有点像b $ b矫枉过正。实际上,大多数时候我只需要字符串类型键和对象

类型值。一个很好的候选人似乎是StringDictionary,我希望使用它可能会对代码效率产生轻微影响。

问候,


Pavils



I mean, most of the time I don''t need "object" key type, it''s sort of
overkill. In fact, most of the time I just need string type key and object
type value. A good candidate for this seems to be StringDictionary, and I
hope that using it could have slight effect on code efficiency.
Regards,

Pavils


Pavils,

除了Jon的评论。
Pavils,
In addition to Jon''s comments.
我对术语收集的理解来自VB,特别是
使用经典ASP进行编程,然后将所有ASP开发转换为JScript
couple

VB6 / ASP Collection不是.NET集合。


在.NET中,你可以使用Microsoft.VisualBasic.Collection来获得与VB6 Collection相同的

功能。


相反然后使用Microsoft.VisualBasic.Collection我使用ArrayList&

a HashTable,或通过继承CollectionBase

或DictionaryBase创建类型安全版本。


希望这有帮助

Jay


Pavils Jurjans < PA **** @ mailbox.riga.lv>在消息中写道

新闻:uf ************** @ TK2MSFTNGP10.phx.gbl ...你好约翰,
My understanding of term "collection" comes from VB, especially programming with classic ASP prior to transerring all ASP developement to JScript couple
A VB6/ASP Collection is not a .NET collection.

Within .NET you can use Microsoft.VisualBasic.Collection to have the same
functionality as a VB6 Collection.

Rather then using Microsoft.VisualBasic.Collection I use either ArrayList &
a HashTable, or create type safe versions by inheriting from CollectionBase
or DictionaryBase.

Hope this helps
Jay

"Pavils Jurjans" <pa****@mailbox.riga.lv> wrote in message
news:uf**************@TK2MSFTNGP10.phx.gbl... Hello John,
不,这是真的 - ICollection *不是*键/值对的集合。
它是一组价值观。你在哪里知道这是一个关键/价值对的集合?
我对术语集合的理解来自VB,特别是
No, it is true - ICollection is *not* a collection of key/value pairs.
It''s a collection of values. Where did you get the idea that it''s a
collection of key/value pairs?
My understanding of term "collection" comes from VB, especially



使用经典ASP进行编程,然后在几年前将所有ASP开发转换为JScript
。因此,在传统的ASP中,例如,我得到一个形式的变量集合。在Request.Form对象中。由于它们可以通过提供
键来读取,因此我认为收集肯定是键值对保持结构。所以,据我的评论看,C#collection应该
不要与VB集合混淆。 Soo ..有一个地方
集合中的项目,或者它就像一个东西,其中的顺序是无关紧要的?我看到对集合中的第一项的引用在许多地方,
显然有某种秩序。但是,有什么意义呢?
集合而不是数组?


programming with classic ASP prior to transerring all ASP developement to JScript couple of years ago. So, in classic ASP, for example, I get "A collection of form
variables" in Request.Form object. Since they are readable by providing key, I was under impression that collection certainly is key-value pair holding
structure. So, as far as I see from your comments, C# collection should not be confused with VB collection. Soo.. is there a "place" of item within
collection, or it''s like a sack with stuff where order of thnks is
irrelevant? I see references to "first item in collection" in many places,
so obviously there is some sort of order. But then, what point is to have
collection instead of array?

System.Hashtable类似乎是最灵活的
代表
The System.Hashtable class seems to be the most flexible representative
字典类,具有键和值类型object。将
Dictionary classes, having both key and value types "object". Would


暗示如果值类型的任一键锚定到一个特定的,它

that imply that if either key of value type is anchored to one specific, it


不再被称为Hastable?


is no more to be called "Hastable"?



我没有完全遵循这句话,但你当然可以在哈希表中使用值
类型,作为键或值。他们最终得到了盒装。



I didn''t quite follow that sentence, but you can certainly use value
types in hashtables, as either keys or values. They just end up getting
boxed.



我的意思是,大部分时间我都不需要反对。关键类型,它有点矫枉过正。实际上,大多数时候我只需要字符串类型键和对象类型值。一个很好的候选人似乎是StringDictionary,我希望使用它可能会对代码效率产生轻微影响。

问候,

Pavils



这篇关于集合与词典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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