一个打乱顺序用的类

从今天开始 我会把自己以前工程中很好用的类  函数一点一点发上来 
一方面是对以前工作的纪念  一方面是让大家一起分享经验  最重要的 是逼迫自己学习新的知识不要抱着经验停滞不前。

用法简单  建立新实例后 
add增加参与的项    
toArray取出乱序数组 
RebuildOrder   重新排序

None.gif
ExpandedBlockStart.gifContractedBlock.gif    
Class RandomListItem Class RandomListItem
InBlock.gif        
Implements System.IComparable
InBlock.gif
InBlock.gif        
Public Value As Object
InBlock.gif        
Public RandomRight As Double
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Function CompareTo()Function CompareTo(ByVal obj As ObjectAs Integer Implements System.IComparable.CompareTo
InBlock.gif            
Dim o As RandomListItem = obj
InBlock.gif            
Return Me.RandomRight - o.RandomRight
ExpandedSubBlockEnd.gif        
End Function

ExpandedBlockEnd.gif    
End Class

None.gif
None.gif
None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif    
Public   Class Factory Class Factory
InBlock.gif        
Dim Base As System.Collections.SortedList
InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Sub New()Sub New()
InBlock.gif            Base 
= New SortedList
ExpandedSubBlockEnd.gif        
End Sub

InBlock.gif
InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Sub Add()Sub Add(ByVal value As Object)
InBlock.gif            
Dim r As New System.Random
InBlock.gif            
Dim i As New RandomListItem
InBlock.gif            i.Value 
= value
InBlock.gif            i.RandomRight 
= r.NextDouble
InBlock.gif            r 
= Nothing
InBlock.gif            Base.Add(Common.MD5CodeStr(i.RandomRight 
& Now), i)
InBlock.gif
ExpandedSubBlockEnd.gif        
End Sub

InBlock.gif
InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Sub AddArray()Sub AddArray(ByVal values As Object())
InBlock.gif            
Dim r As New System.Random
InBlock.gif            
For Each value As Object In values
InBlock.gif
InBlock.gif                
Dim i As New RandomListItem
InBlock.gif                i.Value 
= value
InBlock.gif                i.RandomRight 
= r.NextDouble
InBlock.gif
InBlock.gif                Base.Add(Common.MD5CodeStr(i.RandomRight 
& Now), i)
InBlock.gif            
Next
InBlock.gif            r 
= Nothing
ExpandedSubBlockEnd.gif        
End Sub

InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Function ToArray()Function ToArray(Optional ByVal ArraySize As Int32 = -1As Object()
InBlock.gif            
If ArraySize = -1 Then ArraySize = Base.Count
InBlock.gif            
If ArraySize > Base.Count - 1 Then ArraySize = Base.Count
InBlock.gif            
Dim tmpa() As Collections.DictionaryEntry
InBlock.gif            
If Not Base.Count = 0 Then ReDim tmpa(Base.Count - 1)
InBlock.gif            
Dim r() As Object
InBlock.gif            
If Not Base.Count = 0 Then ReDim r(ArraySize - 1)
InBlock.gif
InBlock.gif            Base.CopyTo(tmpa, 
0)
InBlock.gif
InBlock.gif            
For i As Int32 = 0 To r.Length - 1
InBlock.gif                
Dim ti As RandomListItem = tmpa(i).Value
InBlock.gif                r(i) 
= ti.Value
InBlock.gif            
Next
InBlock.gif            
Return r
ExpandedSubBlockEnd.gif        
End Function

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Function ToHashTable()Function ToHashTable() As Hashtable
InBlock.gif            
Dim x As New Hashtable
InBlock.gif
InBlock.gif            
For Each i As RandomListItem In Base
InBlock.gif                x.Add(Base.GetKey(Base.IndexOfValue(i)), i.Value)
InBlock.gif            
Next
InBlock.gif            
Return x
ExpandedSubBlockEnd.gif        
End Function

InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Sub RebuildOrder()Sub RebuildOrder()
InBlock.gif            
For Each i As RandomListItem In Base
InBlock.gif                
Dim r As New System.Random
InBlock.gif                i.RandomRight 
= r.NextDouble
InBlock.gif                r 
= Nothing
InBlock.gif            
Next
ExpandedSubBlockEnd.gif        
End Sub

ExpandedBlockEnd.gif    
End Class

None.gif
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值