写一个集合 [英] Writing a Collection

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

问题描述




我想写自己的收藏对象。我希望它具有以下

功能。


1 ..它必须是强类型的(对于我写过的类)。

2 ..我应该能够动态添加和删除项目。

3 ..它应该有一个索引器。这将有一个字符串参数。

索引器应返回'ID属性等于

参数的第一项。这些集合通常包含少于10个项目,因此我不打算使用HashTable。

我真的不知道从哪里开始。任何人都知道我在哪里可以找到这样的剂量吗?


加里

Hi

I want to write my own collection object. I want it to have the following
features.

1.. It must be strongly typed (to a Class that I have written).
2.. I should be able to add and remove items dynamically.
3.. It should have an indexer. This will have a string parameter. The
indexer should return the first item that''s ID property is equal to the
parameter. These collections will generally contain less than 10 items, so I
don''t intend to use a HashTable.
I really don''t know where to start. Dose any one know where I can find a
sample which dose something like this?

Gary

推荐答案

您好,


请参阅System.Collections.DictionaryBase

类的文档和示例。它在内部使用HashTable,但是非常便于构建

强类型字典。


另一方面,Hashtable可以针对不同的数量进行优化数据

存储,所以没有理由担心它的性能。


-

Dmitriy Lapshin [C#/ .NET MVP]

X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx

将单元测试的强大功能带到VS .NET IDE


" Gary van der Merwe" < GA ***** @ hotmail.com>在消息中写道

news:eC ************* @ tk2msftngp13.phx.gbl ...
Hi,

See the documentation and examples on the System.Collections.DictionaryBase
class. It uses a HashTable internally, but is very convenient for building
strong-typed dictionaries.

On the other hand, Hashtable can be optimized for different amounts of data
stored so there''s no reason to worry about its performance.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Gary van der Merwe" <ga*****@hotmail.com> wrote in message
news:eC*************@tk2msftngp13.phx.gbl...

<我想写自己的集合对象。我希望它具有以下
功能。

1 ..它必须是强类型的(对于我写过的类)。
2 ..我应该能够动态添加和删除项目。
3 ..它应该有一个索引器。这将有一个字符串参数。
索引器应返回'ID属性等于
参数的第一项。这些收藏品通常包含少于10件物品,所以
我不打算使用HashTable。
我真的不知道从哪里开始。任何人都知道我在哪里可以找到这样的样品吗?

Gary
Hi

I want to write my own collection object. I want it to have the following
features.

1.. It must be strongly typed (to a Class that I have written).
2.. I should be able to add and remove items dynamically.
3.. It should have an indexer. This will have a string parameter. The
indexer should return the first item that''s ID property is equal to the
parameter. These collections will generally contain less than 10 items, so I don''t intend to use a HashTable.
I really don''t know where to start. Dose any one know where I can find a
sample which dose something like this?

Gary






您好


谢谢。这正是我所寻找的。


我查询关于Hashtable性能的观点。为什么MS

然后创建System.Collections.Specialized.HybridDictionary?


我在哪里可以找到HashTable如何在内部工作?
< br $>
Gary

" Dmitriy Lapshin [C#/ .NET MVP]" < X - **** @ no-spam-please.hotpop.com>在消息新闻中写了

:eZ ************* @ TK2MSFTNGP10.phx.gbl ...
Hi

Thanks. That was just what I was looking for.

I query your point regarding the performance of the Hashtable. Why would MS
then create the System.Collections.Specialized.HybridDictionary ?

Where can I find out how a HashTable works internaly?

Gary
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:eZ*************@TK2MSFTNGP10.phx.gbl...


请参阅
System.Collections.DictionaryBase类的文档和示例。它在内部使用HashTable,但是非常便于构建强类型词典。

另一方面,Hashtable可以针对存储的不同数量的
数据进行优化。没有理由担心它的表现。

-
Dmitriy Lapshin [C#/ .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
将单元测试的强大功能带到VS .NET IDE

Gary van der Merwe < GA ***** @ hotmail.com>在消息中写道
新闻:eC ************* @tk2msftngp13.phx.gbl ...
Hi,

See the documentation and examples on the System.Collections.DictionaryBase class. It uses a HashTable internally, but is very convenient for building
strong-typed dictionaries.

On the other hand, Hashtable can be optimized for different amounts of data stored so there''s no reason to worry about its performance.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Gary van der Merwe" <ga*****@hotmail.com> wrote in message
news:eC*************@tk2msftngp13.phx.gbl...


我想写我自己的集合对象。我希望它有
以下功能。

1 ..它必须是强类型的(对于我写过的类)。
2 ..我应该能够动态添加和删除项目。
3 ..它应该有一个索引器。这将有一个字符串参数。
索引器应返回'ID属性等于
参数的第一项。这些集合通常包含少于10个项目,
Hi

I want to write my own collection object. I want it to have the following features.

1.. It must be strongly typed (to a Class that I have written).
2.. I should be able to add and remove items dynamically.
3.. It should have an indexer. This will have a string parameter. The
indexer should return the first item that''s ID property is equal to the
parameter. These collections will generally contain less than 10 items,


所以我

不打算使用HashTable。
我真的不知道在哪里开始。任何人都知道我在哪里可以找到这样的样品吗?

Gary
don''t intend to use a HashTable.
I really don''t know where to start. Dose any one know where I can find a
sample which dose something like this?

Gary




我查询关于Hashtable性能的观点。为什么
MS会创​​建System.Collections.Specialized.HybridDictionary?


根据MSDN,这个类自动适应存储数据的内部存储类型 - 这对用户来说是透明的,

我假设。但是Hashtable本身也可以通过指定

所谓的加载因子进行微调。


我实际上从未测试过少量的Hashtable性能

数据 - 所以可能确实存在与管理查找树相关的开销

等。对于内部实现,我认为应该有一些东西

众所周知(可能来自Donald Knuth关于算法的书)。


-

Dmitriy Lapshin [C#/ .NET MVP]

X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx

将单元测试的强大功能带到VS .NET IDE


Gary van der Merwe < GA ***** @ hotmail.com>在留言中写道

新闻:OI ************** @ tk2msftngp13.phx.gbl ...嗨

谢谢。这正是我所寻找的。

我查询关于Hashtable性能的观点。为什么
MS会创​​建System.Collections.Specialized.HybridDictionary?

我在哪里可以找到HashTable的内部工作方式?

Gary

" Dmitriy Lapshin [C#/ .NET MVP]" < X - **** @ no-spam-please.hotpop.com>在消息新闻中写道
:eZ ************* @ TK2MSFTNGP10.phx.gbl ...
I query your point regarding the performance of the Hashtable. Why would MS then create the System.Collections.Specialized.HybridDictionary ?
According to MSDN, this class automatically accomodates the type of internal
storage to the amount of data stored - and this is transparent to the user,
I assume. But Hashtable itself can also be fine-tuned through specifying the
so called "load factor".

I have actually never tested Hashtable performance for small amounts of
data - so there might really be overhead related to managing lookup trees
etc. As for the internal implementation, I think there should be something
well-known (probably from the Donald Knuth''s book on algorithms).

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Gary van der Merwe" <ga*****@hotmail.com> wrote in message
news:OI**************@tk2msftngp13.phx.gbl... Hi

Thanks. That was just what I was looking for.

I query your point regarding the performance of the Hashtable. Why would MS then create the System.Collections.Specialized.HybridDictionary ?

Where can I find out how a HashTable works internaly?

Gary
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:eZ*************@TK2MSFTNGP10.phx.gbl...


请参阅System.Collections.DictionaryBase
Hi,

See the documentation and examples on the System.Collections.DictionaryBase
类的文档和示例。它在内部使用HashTable,但非常方便
构建
class. It uses a HashTable internally, but is very convenient for building
强类型词典。

另一方面, Hashtable可针对不同数量的
strong-typed dictionaries.

On the other hand, Hashtable can be optimized for different amounts of


数据进行优化


data

存储,因此没有理由担心其性能。

-
Dmitriy Lapshin [C#/ .NET MVP]
X-Unity测试工作室
http://x-unity.miik.com.ua/teststudio.aspx
将单元测试的强大功能带到VS .NET IDE
< br> Gary Gary der Merwe" < GA ***** @ hotmail.com>在消息中写道
新闻:eC ************* @tk2msftngp13.phx.gbl ...
stored so there''s no reason to worry about its performance.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Gary van der Merwe" <ga*****@hotmail.com> wrote in message
news:eC*************@tk2msftngp13.phx.gbl...


我想写我自己的集合对象。我希望它具有
Hi

I want to write my own collection object. I want it to have the


以下功能。

1 ..它必须是强类型的(对于我写过的类)。
2 ..我应该能够动态添加和删除项目。
3 ..它应该有一个索引器。这将有一个字符串参数。
索引器应返回'ID属性等于
参数的第一项。这些集合通常包含少于10
的项目,因此


following features.

1.. It must be strongly typed (to a Class that I have written).
2.. I should be able to add and remove items dynamically.
3.. It should have an indexer. This will have a string parameter. The indexer should return the first item that''s ID property is equal to the parameter. These collections will generally contain less than 10 items, so

不打算使用HashTable。
我真的不喜欢我不知道从哪里开始。任何人都知道我能在哪里找到
don''t intend to use a HashTable.
I really don''t know where to start. Dose any one know where I can find



a样品这样的剂量吗?

Gary


a sample which dose something like this?

Gary







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

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