收藏挑战(MRU) [英] Collections challenge (MRU)

查看:62
本文介绍了收藏挑战(MRU)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先让我说,也许我有一个duh那个时刻,也许我是b $ b缺少一些东西......但在我看来,

System.Collections命名空间中没有任何东西(即使在.NET 2.0中)甚至接近

仍然有用的今天VB内在的Collection。这是挑战(我知道我在这里完全错过了一些东西)....


实现全功能的MRU(最近已使用)清单使用

System.Collections。


使用案例:

1)当前MRU:MyNotes.txt,MySpreadsheet1。 txt,SomeOtherFile.txt

2)用户打开myspreadsheet1.txt (注意案例......文件被重命名

在步骤1和2之间的某个时间

3)新的MRU:MyNotes.txt,SomeOtherFile.txt,* myspreadsheet1.txt * < br $>

要求:


1)物品必须以原始箱子存放,但必须在

集合上搜索不区分大小写。没有使用ToLower存储项目()

欺骗垃圾来解决框架的区分大小写的集合。


2)项目必须保存最旧到最新(或最新到最旧...它不是
真的很重要。)


3)当添加新项目(保留案例)时,弹出一个匹配的项目(案例

不敏感)弹出。

好​​吧,Dictionary(Of String)似乎是答案....作为默认值

Key的比较器不区分大小写...

MRUDictionary.Remove(文件)< - 不区分大小写

MRUDictionary.Add(文件,文件)< - 新案例保存


但是......


4)集合应该允许通过索引访问它必须是可修剪的。

Sub TrimMRU()

如果MRU.Count> 10然后

Dim delta As Integer = MRU.Count - 10

对于Tally As Integer = 1到delta

MRU.RemoveAt(0) ''< - 最旧的物品被移除

下一个理货

结束如果

结束子

字典不支持这个。您无法按索引访问项目。


任何人都有答案?这可以使用Collection轻松完成......但是

没有框架......相当于没有做很多kludgy的事情。代码?


-

-C。 Moya
www.cmoya.com

First let me say that maybe I''m having a "duh" moment and perhaps I''m
missing something... but it seems to me that no one thing in the
System.Collections namespace (even in .NET 2.0) even comes close to the
still-useful-today VB intrinsic Collection. Here''s the challenge (I know I''m
totally missing something here)....

Implement a full featured MRU (Most Recently Used) list using
System.Collections.

Use Case:
1) Current MRU: MyNotes.txt, MySpreadsheet1.txt, SomeOtherFile.txt
2) User opens "myspreadsheet1.txt" (note the case... the file was renamed
sometime between step 1and2
3) New MRU: MyNotes.txt, SomeOtherFile.txt, *myspreadsheet1.txt*

Requirements:

1) Items must be stored in their original case, but searches on the
collection must be case-insensitive. No storing items using ToLower()
cheating crap to work around the framework''s case-sensitive collections.

2) Items must be stored oldest to newest (or newest to oldest... it doesn''t
really matter).

3) When adding a new item (case preserved), a matching item (case
insensitive) already in the collection gets popped out.
Well, Dictionary(Of String) seems to be the answer.... as the default
comparator for Key is case-insensitive...
MRUDictionary.Remove(file) <-- case insensitive
MRUDictionary.Add(file, file) <-- new case preserved

BUT...

4) The collection should allow access by index AND it must be "trimmable."
Sub TrimMRU()
If MRU.Count > 10 Then
Dim delta As Integer = MRU.Count - 10
For tally As Integer = 1 To delta
MRU.RemoveAt(0) ''<-- oldest items removed
Next tally
End If
End Sub
Dictionary does not support this. You cannot access items "by index."

Anyone have an answer? This is easily done using "Collection"...... but is
there no "framework" equivalent without doing a lot of "kludgy" code?

--
-C. Moya
www.cmoya.com

推荐答案

哦,集合必须是可序列化的(比如,能够存储在

My.Settings中)。


自原帖以来,我决定忘掉它。并使用

内在的VB Collection对象......但却发现它不可序列化......

所以这些值不能存储在我的设置。当然,我可以写一个算法

来转换它...但是,我正在寻找一个简单的非kludgy解决方案。


-

-C。 Moya
www.cmoya.com

" CMM" < cm*@nospam.com>在留言中写道

新闻:OY **************** @ TK2MSFTNGP12.phx.gbl ...
Oh and the collection must be serializable (like, able to be stored in
My.Settings).

Since the original post, I decided to just "forget about it" and go with the
intrinsic VB Collection object... only to find that it''s not serializable...
so the values can''t be stored in My.Settings. Sure, I can write an algorithm
to convert it... but, I''m looking for an easy non-kludgy solution.

--
-C. Moya
www.cmoya.com
"CMM" <cm*@nospam.com> wrote in message
news:OY****************@TK2MSFTNGP12.phx.gbl...
首先让我说,也许我有一个duh那个时刻,也许我错过了一些东西......但在我看来,
System.Collections命名空间(即使在.NET 2.0中)也没有任何东西可以接近
仍然有用 - 今天的VB内在集合。这是挑战(我知道
我在这里完全遗漏了一些东西)....

使用
实现一个功能齐全的MRU(最近使用的)列表System.Collections。

使用案例:
1)当前MRU:MyNotes.txt,MySpreadsheet1.txt,SomeOtherFile.txt
2)用户打开myspreadsheet1.txt (注意案例......文件在步骤1和2之间的某个时间重命名
3)新的MRU:MyNotes.txt,SomeOtherFile.txt,* myspreadsheet1.txt *

要求:

1)项目必须以原始案例存储,但对
集合的搜索必须不区分大小写。没有使用ToLower存储物品()
欺骗垃圾来解决框架的区分大小写的集合。

2)项目必须保存最旧到最新(或最新到最旧..它并不重要。

3)当添加一个新项目(保留大小写)时,集合中已经存在一个匹配的项目(不区分大小写)弹出来。
好吧,Dictionary(Of String)似乎就是答案....因为Key的默认比较器是不区分大小写的...
MRUDictionary.Remove(file) < - 不区分大小写
MRUDictionary.Add(文件,文件)< - 保留新案例

但是......

4)集合应该允许通过索引进行访问并且它必须是可修剪的。
Sub TrimMRU()
如果MRU.Count> 10然后
Dim delta As Integer = MRU.Count - 10
对于Tally As Integer = 1到delta
MRU.RemoveAt(0)''< - 删除最旧的项目下一个记录
结束如果
结束Sub
Dictionary不支持这个。您无法按索引访问项目。

任何人都有答案?这可以使用收集轻松完成......但是没有框架......相当于没有做很多kludgy的事情。代码?

-
-C。 Moya
www.cmoya.com
First let me say that maybe I''m having a "duh" moment and perhaps I''m
missing something... but it seems to me that no one thing in the
System.Collections namespace (even in .NET 2.0) even comes close to the
still-useful-today VB intrinsic Collection. Here''s the challenge (I know
I''m totally missing something here)....

Implement a full featured MRU (Most Recently Used) list using
System.Collections.

Use Case:
1) Current MRU: MyNotes.txt, MySpreadsheet1.txt, SomeOtherFile.txt
2) User opens "myspreadsheet1.txt" (note the case... the file was renamed
sometime between step 1and2
3) New MRU: MyNotes.txt, SomeOtherFile.txt, *myspreadsheet1.txt*

Requirements:

1) Items must be stored in their original case, but searches on the
collection must be case-insensitive. No storing items using ToLower()
cheating crap to work around the framework''s case-sensitive collections.

2) Items must be stored oldest to newest (or newest to oldest... it
doesn''t really matter).

3) When adding a new item (case preserved), a matching item (case
insensitive) already in the collection gets popped out.
Well, Dictionary(Of String) seems to be the answer.... as the default
comparator for Key is case-insensitive...
MRUDictionary.Remove(file) <-- case insensitive
MRUDictionary.Add(file, file) <-- new case preserved

BUT...

4) The collection should allow access by index AND it must be "trimmable."
Sub TrimMRU()
If MRU.Count > 10 Then
Dim delta As Integer = MRU.Count - 10
For tally As Integer = 1 To delta
MRU.RemoveAt(0) ''<-- oldest items removed
Next tally
End If
End Sub
Dictionary does not support this. You cannot access items "by index."

Anyone have an answer? This is easily done using "Collection"...... but is
there no "framework" equivalent without doing a lot of "kludgy" code?

--
-C. Moya
www.cmoya.com



Carlos,


甚至Herfried同意旧的VB集合应该放在VB兼容命名空间的
中正常的VB命名空间。应该没有使用
。它与Net

(AFAIK实现所有ICollection)中的任何其他集合有很大不同,令人尴尬的是

名称保持不变。


只是我的想法,


Cor


" CMM" < cm*@nospam.com> schreef in bericht

新闻:OB ************** @ TK2MSFTNGP11.phx.gbl ...
Carlos,

Even Herfried agrees that the old VB collection should have been placed in
the VB compatible namespace instead in the normal VB namespace. It should
not been used. It is so much different from any other collection in Net
(which AFAIK implements all ICollection) that it is embarrassing that the
names are kept the same.

Just my thought,

Cor

"CMM" <cm*@nospam.com> schreef in bericht
news:OB**************@TK2MSFTNGP11.phx.gbl...
哦,收藏必须是可序列化的(比如,能够存储在我的.Settings中)。

从最初的帖子开始,我决定只是忘掉它。并使用
内部的VB Collection对象...只是发现它不可序列化......所以这些值不能存储在My.Settings中。当然,我可以写一个算法来转换它...但是,我正在寻找一个简单的非kludgy解决方案。

-
-C。 Moya
www.cmoya.com
CMM < cm*@nospam.com>在消息中写道
新闻:OY **************** @ TK2MSFTNGP12.phx.gbl ...
Oh and the collection must be serializable (like, able to be stored in
My.Settings).

Since the original post, I decided to just "forget about it" and go with
the intrinsic VB Collection object... only to find that it''s not
serializable... so the values can''t be stored in My.Settings. Sure, I can
write an algorithm to convert it... but, I''m looking for an easy
non-kludgy solution.

--
-C. Moya
www.cmoya.com
"CMM" <cm*@nospam.com> wrote in message
news:OY****************@TK2MSFTNGP12.phx.gbl...
首先让我说也许我有一个duh那个时刻,也许我错过了一些东西......但在我看来,
System.Collections命名空间(即使在.NET 2.0中)也没有任何东西可以接近
仍然有用 - 今天的VB内在集合。这是挑战(我知道
我在这里完全遗漏了一些东西)....

使用
实现一个功能齐全的MRU(最近使用的)列表System.Collections。

使用案例:
1)当前MRU:MyNotes.txt,MySpreadsheet1.txt,SomeOtherFile.txt
2)用户打开myspreadsheet1.txt (注意案例......文件在步骤1和2之间的某个时间重命名
3)新的MRU:MyNotes.txt,SomeOtherFile.txt,* myspreadsheet1.txt *

要求:

1)项目必须以原始案例存储,但对
集合的搜索必须不区分大小写。没有使用ToLower存储物品()
欺骗垃圾来解决框架的区分大小写的集合。

2)项目必须保存最旧到最新(或最新到最旧..它并不重要。

3)当添加一个新项目(保留大小写)时,集合中已经存在一个匹配的项目(不区分大小写)弹出来。
好吧,Dictionary(Of String)似乎就是答案....因为Key的默认比较器是不区分大小写的...
MRUDictionary.Remove(file) < - 不区分大小写
MRUDictionary.Add(文件,文件)< - 保留新案例

但是......

4)集合应该允许通过索引访问并且它必须是可修剪的。
Sub TrimMRU()
如果MRU.Count> 10然后
Dim delta As Integer = MRU.Count - 10
对于Tally As Integer = 1到delta
MRU.RemoveAt(0)''< - 删除最旧的项目下一个记录
结束如果
结束Sub
Dictionary不支持这个。您无法按索引访问项目。

任何人都有答案?这可以使用收集轻松完成......但是
没有框架。相当于没有做很多kludgy的事情。代码?

-
-C。 Moya
www.cmoya.com
First let me say that maybe I''m having a "duh" moment and perhaps I''m
missing something... but it seems to me that no one thing in the
System.Collections namespace (even in .NET 2.0) even comes close to the
still-useful-today VB intrinsic Collection. Here''s the challenge (I know
I''m totally missing something here)....

Implement a full featured MRU (Most Recently Used) list using
System.Collections.

Use Case:
1) Current MRU: MyNotes.txt, MySpreadsheet1.txt, SomeOtherFile.txt
2) User opens "myspreadsheet1.txt" (note the case... the file was renamed
sometime between step 1and2
3) New MRU: MyNotes.txt, SomeOtherFile.txt, *myspreadsheet1.txt*

Requirements:

1) Items must be stored in their original case, but searches on the
collection must be case-insensitive. No storing items using ToLower()
cheating crap to work around the framework''s case-sensitive collections.

2) Items must be stored oldest to newest (or newest to oldest... it
doesn''t really matter).

3) When adding a new item (case preserved), a matching item (case
insensitive) already in the collection gets popped out.
Well, Dictionary(Of String) seems to be the answer.... as the default
comparator for Key is case-insensitive...
MRUDictionary.Remove(file) <-- case insensitive
MRUDictionary.Add(file, file) <-- new case preserved

BUT...

4) The collection should allow access by index AND it must be
"trimmable."
Sub TrimMRU()
If MRU.Count > 10 Then
Dim delta As Integer = MRU.Count - 10
For tally As Integer = 1 To delta
MRU.RemoveAt(0) ''<-- oldest items removed
Next tally
End If
End Sub
Dictionary does not support this. You cannot access items "by index."

Anyone have an answer? This is easily done using "Collection"...... but
is there no "framework" equivalent without doing a lot of "kludgy" code?

--
-C. Moya
www.cmoya.com




怎么样?我同意是否有一个具有相同

功能的替代方案。到目前为止,从我所看到的,没有一个基于框架的

集合可以完成VB-Collection所做的...因为它是混合的

字典和列表。字典不保持FIFO顺序...并且列表是

没有键入。


也许我错过了什么? :-)


Hey Cor ... hotshot ...解决MRU问题。 ;-)


-

-C。 Moya
www.cmoya.com

" Cor Ligthert [MVP]" <无************ @ planet.nl>在消息中写道

news:%2 **************** @ TK2MSFTNGP11.phx.gbl ...
How so? I would agree if there was an alternative with all the same
features. So far, from what I have seen, there is NOT ONE framework-based
collection that does what VB-Collection does... as it is a hybrid of
Dictionary and List. Dictionary does not maintain FIFO order... and List is
not Keyed.

Maybe I''m missing something? :-)

Hey Cor... hotshot... solve the MRU problem. ;-)

--
-C. Moya
www.cmoya.com
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Carlos,

即使Herfried同意旧的VB集合应该放在VB兼容的命名空间中,而不是普通的VB命名空间。它应该没有被使用过。它与Net
中的任何其他系列(AFAIK实现所有ICollection)有很大不同,令人尴尬的是
名称保持不变。

只是我的想法,

Cor

CMM < cm*@nospam.com> schreef in bericht
新闻:OB ************** @ TK2MSFTNGP11.phx.gbl ...
Carlos,

Even Herfried agrees that the old VB collection should have been placed in
the VB compatible namespace instead in the normal VB namespace. It should
not been used. It is so much different from any other collection in Net
(which AFAIK implements all ICollection) that it is embarrassing that the
names are kept the same.

Just my thought,

Cor

"CMM" <cm*@nospam.com> schreef in bericht
news:OB**************@TK2MSFTNGP11.phx.gbl...
哦,集合必须是可序列化的(如,能够存储在
My.Settings中。

从最初的帖子开始,我决定只是忘掉它。并使用
内部的VB Collection对象...只是发现它不可序列化......所以这些值不能存储在My.Settings中。当然,我可以写一个算法来转换它...但是,我正在寻找一个简单的非kludgy解决方案。

-
-C。 Moya
www.cmoya.com
CMM < cm*@nospam.com>在消息中写道
新闻:OY **************** @ TK2MSFTNGP12.phx.gbl ...
Oh and the collection must be serializable (like, able to be stored in
My.Settings).

Since the original post, I decided to just "forget about it" and go with
the intrinsic VB Collection object... only to find that it''s not
serializable... so the values can''t be stored in My.Settings. Sure, I can
write an algorithm to convert it... but, I''m looking for an easy
non-kludgy solution.

--
-C. Moya
www.cmoya.com
"CMM" <cm*@nospam.com> wrote in message
news:OY****************@TK2MSFTNGP12.phx.gbl...
首先让我说也许我有一个duh那个时刻,也许我错过了一些东西......但在我看来,
System.Collections命名空间(即使在.NET 2.0中)也没有任何东西可以接近
仍然有用 - 今天的VB内在集合。这是挑战(我知道
我在这里完全遗漏了一些东西)....

使用
实现一个功能齐全的MRU(最近使用的)列表System.Collections。

使用案例:
1)当前MRU:MyNotes.txt,MySpreadsheet1.txt,SomeOtherFile.txt
2)用户打开myspreadsheet1.txt (注意案例......文件在步骤1和2之间的某个时间重命名。
3)新的MRU:MyNotes.txt,SomeOtherFile.txt,* myspreadsheet1.txt *

要求:

1)项目必须以原始案例存储,但对
集合的搜索必须不区分大小写。没有使用ToLower存储物品()
欺骗垃圾来解决框架的区分大小写的集合。

2)项目必须保存最旧到最新(或最新到最旧..它并不重要。

3)当添加一个新项目(保留大小写)时,集合中已经存在一个匹配的项目(不区分大小写)弹出来。
好吧,Dictionary(Of String)似乎就是答案....因为Key的默认比较器是不区分大小写的...
MRUDictionary.Remove(file) < - 不区分大小写
MRUDictionary.Add(文件,文件)< - 保留新案例

但是......

4)集合应该允许通过索引访问并且它必须是可修剪的。
Sub TrimMRU()
如果MRU.Count> 10然后
Dim delta As Integer = MRU.Count - 10
对于Tally As Integer = 1到delta
MRU.RemoveAt(0)''< - 删除最旧的项目下一个记录
结束如果
结束Sub
Dictionary不支持这个。您无法按索引访问项目。

任何人都有答案?这可以使用收集轻松完成......但是
没有框架。相当于没有做很多kludgy的事情。代码?

-
-C。 Moya
www.cmoya.com
First let me say that maybe I''m having a "duh" moment and perhaps I''m
missing something... but it seems to me that no one thing in the
System.Collections namespace (even in .NET 2.0) even comes close to the
still-useful-today VB intrinsic Collection. Here''s the challenge (I know
I''m totally missing something here)....

Implement a full featured MRU (Most Recently Used) list using
System.Collections.

Use Case:
1) Current MRU: MyNotes.txt, MySpreadsheet1.txt, SomeOtherFile.txt
2) User opens "myspreadsheet1.txt" (note the case... the file was
renamed sometime between step 1and2
3) New MRU: MyNotes.txt, SomeOtherFile.txt, *myspreadsheet1.txt*

Requirements:

1) Items must be stored in their original case, but searches on the
collection must be case-insensitive. No storing items using ToLower()
cheating crap to work around the framework''s case-sensitive collections.

2) Items must be stored oldest to newest (or newest to oldest... it
doesn''t really matter).

3) When adding a new item (case preserved), a matching item (case
insensitive) already in the collection gets popped out.
Well, Dictionary(Of String) seems to be the answer.... as the default
comparator for Key is case-insensitive...
MRUDictionary.Remove(file) <-- case insensitive
MRUDictionary.Add(file, file) <-- new case preserved

BUT...

4) The collection should allow access by index AND it must be
"trimmable."
Sub TrimMRU()
If MRU.Count > 10 Then
Dim delta As Integer = MRU.Count - 10
For tally As Integer = 1 To delta
MRU.RemoveAt(0) ''<-- oldest items removed
Next tally
End If
End Sub
Dictionary does not support this. You cannot access items "by index."

Anyone have an answer? This is easily done using "Collection"...... but
is there no "framework" equivalent without doing a lot of "kludgy" code?

--
-C. Moya
www.cmoya.com





这篇关于收藏挑战(MRU)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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