views:

97

answers:

1

What is the best way to use to the Profile feature to store a users last 10 searchs.

Basically I need some kind of circular array, but not sure how to implement. One option is to write a static (Shared) function somewhere that

  Public Shared Sub  AddSearch(strSearch as  String)
     Profile.Search1= Profile.Search2
     Profile.Search2= Profile.Search3
       .....
       .....
       .....
     Profile.Search10= strSearch 

  End  Sub

Any thoughts on something less clunky?

+1  A: 

A couple of years ago I wrote a database stored procedure that did this, but it occurs to me there may be a better way by using a Queue.

<properties>
  <add name="Searches" type="System.Collections.Queue" serializeAs="Xml" />
</properties>

Public Shared Sub AddSearch(strSearch as String)  

    Dim searches As Queue

    searches = Profile.searches

    If searches.Count = 10 Then
        'Remove the first element from the queue so we make space for a new one
        searches.Dequeue()
    End If

    searches.Enqueue(strSearch)

End  Sub  

A Queue(Of String) would be even nicer but I can't get the compiler to accept it from the web.config.

PhilPursglove