Asp.Net Pdf

Topics: Madrid Metro, Class, .NET Framework Pages: 112 (33971 words) Published: February 8, 2011
ASP.NET: Tips, Tutorials, and Code
Scott Mitchell, Bill Anders, Rob Howard, Doug Seven, Stephen Walther, Christop Wille, and Don Wolthuis

201 West 103rd St., Indianapolis, Indiana, 46290 USA
0-672-32143-2 Spring 2001

Common ASP.NET Code Techniques



• Using Collections 4 • Working with the File System • Using Regular Expressions 45 51 60 64

• Generating Images Dynamically

• Sending E-mail from an ASP.NET Page • Network Access Via an ASP.NET Page

• Uploading Files from the Browser to the Web Server Via an ASP.NET Page 71 • Using ProcessInfo: Retrieving Information About a Process 79 • Accessing the Windows Event Log • Working with Server Performance Counters 93 • Encrypting and Decrypting Information 101 84


Common ASP.NET Code Techniques CHAPTER 2

Using Collections
Most modern programming languages provide support for some type of object that can hold a variable number of elements. These objects are referred to as collections, and they can have elements added and removed with ease without having to worry about proper memory allocation. If you’ve programmed with classic ASP before, you’re probably familiar with the Scripting.Dictionary object, a collection object that references each element with a textual key. A collection that stores objects in this fashion is known as a hash table. There are many types of collections in addition to the hash table. Each type of collection is similar in purpose: it serves as a means to store a varying number of elements, providing an easy way, at a minimum, to add and remove elements. Each different type of collection is unique in its method of storing, retrieving, and referencing its various elements. The .NET Framework provides a number of collection types for the developer to use. In fact, an entire namespace, System.Collections, is dedicated to collection types and helper classes. Each of these collection types can store elements of type Object. Because in .NET all primitive data types—string, integers, date/times, arrays, and so on—are derived from the Object class, these collections can literally store anything! For example, you could use a single collection to store a couple of integers, an instance of a classic COM component, a string, a date/time, and two instances of a custom-written .NET component. Most of the examples in this section use collections to house primitive data types (strings, integers, doubles). However, Listing 2.1 illustrates a collection of collections—that is, a collection type that stores entire collections as each of its elements! Throughout this section we’ll examine five collections the .NET Framework offers developers: the ArrayList, the Hashtable, the SortedList, the Queue, and the Stack. As you study each of these collections, realize that they all have many similarities. For example, each type of collection can be iterated through element-by-element using a For Each ... Next loop in VB (or a foreach loop in C#). Each collection type has a number of similarly named functions that perform the same tasks. For example, each collection type has a Clear method that removes all elements from the collection, and a Count property that returns the number of elements in the collection. In fact, the last subsection “Similarities Among the Collection Types” examines the common traits found among the collection types.

Working with the ArrayList Class
The first type of collection we’ll look at is the ArrayList. With an ArrayList, each item is stored in sequential order and is indexed numerically. In our following examples, keep in mind that the developer need not worry himself with memory allocation. With the standard array, the

Common ASP.NET Code Techniques CHAPTER 2


developer cannot easily add and remove elements without concerning himself with the size and makeup of the array. With all the collections we’ll examine in this chapter, this is no longer a concern.

Adding, Removing,...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Objectives on Asp.Net Essay
  • Essay about Intoduction to Asp.Net
  • Asp.Net Essay
  • Asp.Net Research Paper
  • 70-564cshp
  • ASP.NET Performance and Scalability Improvements Essay
  • Asp.Net in Action Essay
  • Pdfs Essay

Become a StudyMode Member

Sign Up - It's Free