.Net 3.5 中的 ASP.Net 配置文件对象

发布于 2024-09-01 06:41:48 字数 357 浏览 2 评论 0原文

使用个人资料功能存储用户最近 10 次搜索的最佳方式是什么?

基本上我需要某种圆形数组,但不知道如何实现。一种选择是在某个地方编写一个静态(共享)函数,

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

  End  Sub

您对不那么笨重的东西有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤芳又自赏 2024-09-08 06:41:48

几年前,我编写了一个数据库存储过程来执行此操作,但我突然想到使用队列可能有更好的方法。

<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  

Queue(Of String) 会更好,但我无法让编译器从 web.config 接受它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文