且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

帮助排序包含结构的Arraylist

更新时间:2023-11-24 09:01:22

贾斯汀,


一个选项是让您的结构实现IComparable接口:


结构TabStructure

实现IComparable(Of TabStructure)

Dim TabName As String

Dim FullFilePath As String


函数CompareTo(ByVal other As TabStructure)作为整数

实现IComparable (TabStructure)。比较


返回Me.TabName.CompareTo(other.TabName)


结束功能
>
结束结构


现在ArrayList.Sort应该对标签进行排序。通过TabName。


顺便说一下,我会使用一个类而不是一个结构。


Kerry Moorman
>
" Justin"写道:
Justin,

One option is to have your structure implement the IComparable interface:

Structure TabStructure
Implements IComparable(Of TabStructure)
Dim TabName As String
Dim FullFilePath As String

Function CompareTo(ByVal other As TabStructure) As Integer
Implements IComparable(Of TabStructure).CompareTo

Return Me.TabName.CompareTo(other.TabName)

End Function

End Structure

Now ArrayList.Sort should sort the "tabs" by TabName.

By the way, I would use a class instead of a structure.

Kerry Moorman

"Justin" wrote:

好​​的,我放弃了。我似乎无法构建一个体面的(有效的)方式来分类我的arraylist。


我有两个元素的结构:


结构TabStructure

Dim TabName As String

Dim FullFilePath As String

结束结构


然后例如我:


Dim tab作为New TabStructure


一些代码

>
然后我添加tab到某个arraylist。


在某些时候,我遍历我的arraylist,抓取数据并从

创建标签。当然结果列表的选项卡是不按顺序的。


有人可以帮我按字母顺序排序我的数组列表

TabStructure.TabName?


我将不胜感激。

Ok, I give up. I can''t seem to construct a decent (productive) way of
sorting my arraylist.

I have a structure of two elements:

Structure TabStructure
Dim TabName As String
Dim FullFilePath As String
End Structure

Then for example I:

Dim tab as New TabStructure

some code

Then I add "tab" to an arraylist.

At some point I loop through my arraylist, grab data and create tabs from
it. Of course the resulting list of tabs are out of sequence.

Can someone help me to sort my array list alphabetically by
TabStructure.TabName?

I would greatly appreciate it.


嗨贾斯汀,


首先,你为什么要使用ArrayList?您应该使用通用列表,例如。


将myList作为新列表(TabStructure)的暗淡格式


然后,假设您使用的是VB 2008 ,你可以传入一个lambda函数来获得
的排序方法:


myList.Sort(Function(x,y)x.TabName.CompareTo(y .TabName))



" Justin" < No ** @ None.comwrote in message

news:OE **************** @ TK2MSFTNGP03.phx.gbl ...
Hi Justin,

First, why are you using ArrayList ? You should use the generic List, eg.

Dim myList as New List(Of TabStructure)

Then, assuming you are using VB 2008, you can pass in a lambda function to
the sort method:

myList.Sort(Function(x, y) x.TabName.CompareTo(y.TabName))



"Justin" <No**@None.comwrote in message
news:OE****************@TK2MSFTNGP03.phx.gbl...

好​​的,我放弃了。我似乎无法构建一个体面的(有效的)方式来分类我的arraylist。


我有两个元素的结构:


结构TabStructure

Dim TabName As String

Dim FullFilePath As String

结束结构


然后例如我:


Dim tab作为New TabStructure


一些代码

>
然后我添加tab到某个arraylist。


在某些时候,我遍历我的arraylist,抓取数据并从

创建标签。当然结果列表的选项卡是不按顺序的。


有人可以帮我按字母顺序排序我的数组列表

TabStructure.TabName?


我会非常感激。
Ok, I give up. I can''t seem to construct a decent (productive) way of
sorting my arraylist.

I have a structure of two elements:

Structure TabStructure
Dim TabName As String
Dim FullFilePath As String
End Structure

Then for example I:

Dim tab as New TabStructure

some code

Then I add "tab" to an arraylist.

At some point I loop through my arraylist, grab data and create tabs from
it. Of course the resulting list of tabs are out of sequence.

Can someone help me to sort my array list alphabetically by
TabStructure.TabName?

I would greatly appreciate it.


首先,直到现在我才听说过list。但是你特别提到VS2008

而我正在使用VS2008我想继续使用框架2的

范围。你的建议是否这样做?如果是这样,那么我会在上面阅读



谷歌搜索VB.NET列表我只想出了arraylists和listbox。


我已经知道arraylists了,我已经知道如何在

添加之前检查重复数据,所以这很简单敲响了代码。这个arraylist在我的应用程序中使用了




" Bill McCarthy" < Bi ** @ localhost.comwrote in message

news:12 **************************** ****** @ microsof t.com ...
First, until just now I never heard of "lists". However you mention VS2008
specifically and while I am using VS2008 I''m wanting to stay with in the
confines of framework 2. Does your suggestion do that? If so then I''ll
read up on it.

Googling "VB.NET list" came up with nothing but arraylists and listboxes.

I already know arraylists and I already know how to check for dups before
adding so it was pretty simple to bang out the code. This arraylist is used
all over my app.

"Bill McCarthy" <Bi**@localhost.comwrote in message
news:12**********************************@microsof t.com...

嗨贾斯汀,


首先,你为什么使用ArrayList?您应该使用通用列表,例如。


将myList作为新列表(TabStructure)的暗淡格式


然后,假设您使用的是VB 2008 ,你可以传入一个lambda函数来获得
的排序方法:


myList.Sort(Function(x,y)x.TabName.CompareTo(y .TabName))



" Justin" < No ** @ None.comwrote in message

news:OE **************** @ TK2MSFTNGP03.phx.gbl ...
Hi Justin,

First, why are you using ArrayList ? You should use the generic List, eg.

Dim myList as New List(Of TabStructure)

Then, assuming you are using VB 2008, you can pass in a lambda function to
the sort method:

myList.Sort(Function(x, y) x.TabName.CompareTo(y.TabName))



"Justin" <No**@None.comwrote in message
news:OE****************@TK2MSFTNGP03.phx.gbl...

>好的,我放弃了。我似乎无法构建一种体面的(高效的)方式来整理我的arraylist。

我有两个元素的结构:

结构TabStructure
Dim TabName As String
Dim FullFilePath As String
结束结构

然后例如我:

Dim tab as New TabStructure

一些代码

然后我添加tab到某个arraylist。

在某些时候,我遍历我的arraylist,抓取数据并从
创建标签。当然结果列表的选项卡是不按顺序的。

有人可以帮我按字母顺序对我的数组列表进行排序吗?
TabStructure.TabName?

我会很大的欣赏它。
>Ok, I give up. I can''t seem to construct a decent (productive) way of
sorting my arraylist.

I have a structure of two elements:

Structure TabStructure
Dim TabName As String
Dim FullFilePath As String
End Structure

Then for example I:

Dim tab as New TabStructure

some code

Then I add "tab" to an arraylist.

At some point I loop through my arraylist, grab data and create tabs from
it. Of course the resulting list of tabs are out of sequence.

Can someone help me to sort my array list alphabetically by
TabStructure.TabName?

I would greatly appreciate it.