[ Team LiB ] |
13.2 Properties Reference
Returns an integer containing the number of items currently in the Application collection. The Count member is derived from the ICollection interface, which is implemented by the HttpApplicationState class. Parameter
ExampleThe example adds two values to the Application collection, displays the count of items in the Application collection, and then uses the Count property as a looping control value to display each item: Sub Page_Load( ) Application.Clear( ) Application("foo") = "Hello, " Application("bar") = "World!" Message.Text = "The Application collection contains " & _ Application.Count & " items: " Dim I as Integer For I = 0 To Application.Count - 1 Message.Text &= Application(I) Next End Sub NotesThe Count property is new for ASP.NET. In addition to using the Count property for looping through the Application collection, you can use the property to keep track of how many items the Application stores at any given time. For example, you could write this information to a log for later review.
Returns or sets an Object associated with a particular name or index. Parameters
ExampleThe example sets the values of two items in the Application collection. If these items do not already exist in the collection, they will be added. The example then displays the two values. Sub Page_Load( ) Application.Clear( ) Application.Item("foo") = "foo" Application.Item("foo2") = "foo2" Message.Text = Application.Item("foo") & "<br/>" Message.Text &= Application.Item(1) End Sub NotesThe Item property is accessed implicitly when using the syntax: Application("foo") = "foo" This syntax is often seen in classic ASP code. Explicitly referencing the Item property is not required, but listing it may make your code more readable and understandable than accessing it implicitly. Note that an index may be used as an argument only when modifying a value, not when creating a new item, and the index must be less than the number of items in the Application collection, or an exception will be thrown. |
[ Team LiB ] |