您现在的位置: 无忧电子商务网 >> 信息学院 >> 程序开发 >> asp.net >> 正文

Common ASP.NET Code Techniques (DPC&DWC Reference)--6

作者:作者:未…    信息学院来源:网络收集    点击数:    更新时间:2006-8-28 我要参与讨论

  lement; line 13 uses the Redirect method of the Response object to send the user to the next element at the top of the stack.

That wraps up our examination of the navigation history stack example. The code samples spanned three listings: Listing 2.1.5, Listing 2.1.6, and Listing 2.1.7. If you decide to use this code on your Web site, there are a couple of things to keep in mind:

First, because our implementation of the navigation history stack is a code snippet in an ASP.NET page, the code in Listing 2.1.5 would need to appear in every Web page on your site. This, of course, is a ridiculous requirement; it would make sense to encapsulate the code and functionality in a user control to allow for easy code reuse. (For more information on user controls, refer to Chapter 5, "Creating and Using User Controls.")

Second, remember that in Back.CSharp.aspx we are Popping off the top two URLs. Because Pop removes these elements from the Stack altogether, the navigation history stack cannot contain any sort of Forward link.

Similarities Among the Collection Types
Because each collection has the same basic functionality—to serve as a variable-sized storage medium for Objects—it is not surprising that the collection types have much in common with one another. All have methods to add and remove elements from the collection. The Count property, which returns the total number of elements in the collection, is common among all collection types.

Each collection also has a means to iterate through each element. This can be accomplished in VB using a For Each ... Next loop or, in C#, a foreach loop, as follows:

'With VB, use a For Each ... Next Loop
Dim qTasks as Queue = New Queue()

' ... Populate the Queue ...

Dim s as String
For Each s in qTasks
's represents the current element in qTasks
Response.Write(s + "<br>")
Next


// In C#, a foreach construct can be used to iterate
// through each element
Queue qTasks = new Queue();

// ... Populate the Queue ...

foreach (String s in qTasks)
{
  // s represents the current element in qTasks
  Response.Write(s + "<br>");
}
Although each collection can be iterated via a For Each ... Next or foreach loop, each collection can also have its elements iterated with an enumerator. Enumerators are small classes that provide a simple functionality: to serve as a (read-only) cursor to allow the developer to step through the elements of a collection.

The .NET Framework provides a number of specific enumerators for specific collection types. For example,the IDictionaryElement enumerator is useful for iterating through a Hashtable. The IList enumerator is handy for stepping through the elements of an ArrayList. All these specialized enumerators are derived from a base enumerator interface, IEnumerator. Because of this fact, all the collectio

上一页  [1] [2] [3] [4] [5] [6] 下一页

在google里搜索更多Common ASP.NET Code Techniques (DPC&DWC Reference)--6

Google
Web www.51ec.org
【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
我来说两句 对此文章发表了评论
  昵 称: *必填    ·注册用户·
  评 分: 1分 2分 3分 4分 5分     严禁发表危害国家安全、政治、黄色淫秽等内容的评论,用户需对自己在使用本网站服务过程中的行为承担法律责任。本站管理员有权保留或删除评论内容,评论内容只代表机友个人观点,与本网站立场无关。  
评 论
内 容

 
评论列表 (最新 评论仅限网友观点!)

供求信息




| 设为首页 | 加入收藏 | 关于我们 | 广告服务 | 联系方式 | 友情链接 | 版权申明