다음을 통해 공유


Application.Contents.Remove Method

The Contents.Remove method for ASP deletes an item from the Application.Contents collection.

Contents.Remove(
      id
)

Parameters

  • id
    A string or an integer identifying the item in the colleciton to be removed. If id is a string, the method searches the contents collection for an item with that name and removes it. If id is an integer, the method counts that number of items from the start of the collection and removes the corresponding item.

    Caution

    When id is an integer, the index numbers of all items in the collection are updated. It is recommended that you always identify an item in a collection by its name.

Return Values

This method has no return values.

Remarks

Although ASP collections are similar to the Visual Basic Collection object, there are some differences. ASP collections support the Count property and the Item, Remove, and RemoveAll methods. They do not support the Add method.

Example Code

The following example adds three items to the Application.Contents collection and removes two. At the end of the example, Application(str3) is the first item instead of the third.

<%@ Language="VBScript" %> 
<% 
  Response.Write("<br/>Before Remove<br/>") 
  Application.Lock 
  Application.Contents.Item("str1") = ("First thing") 
  Application.Contents("str2") = ("Second thing") 
  Application("str3") = ("Third thing") 
  Application.Unlock 
  For Each Key in Application.Contents 
    Response.Write Key + " = " + Application(Key) + "<br/>" 
  Next 
  Response.Write("<br/>After Remove<br/>") 
  Application.Lock 
  Application.Contents.Remove("str1") 
  Application.Contents.Remove("str2") 
  Application.Unlock 
  For Each Key in Application.Contents 
    Response.Write Key + " = " + Application(Key) + "<br/>" 
  Next 
%> 

<%@ Language="JScript" %> 
<% 
  Response.Write("<br/>Before Remove<br/>"); 
  Application.Lock(); 
  Application.Contents.Item("str1") = ("First thing"); 
  Application.Contents("str2") = ("Second thing"); 
  Application("str3") = ("Third thing"); 
  Application.Unlock(); 
  e = new Enumerator(Application.Contents); 
  for (; !e.atEnd(); e.moveNext()) { 
    Response.Write(e.item() + " = " + Application(e.item()) + "<br/>");  
  } 
  Response.Write("<br/>After Remove<br/>"); 
  Application.Lock(); 
  Application.Contents.Remove("str1"); 
  Application.Contents.Remove("str2"); 
  Application.Unlock(); 
  e = new Enumerator(Application.Contents); 
  for (; !e.atEnd(); e.moveNext()) { 
    Response.Write(e.item() + " = " + Application(e.item()) + "<br/>");  
  } 
%> 

Requirements

Client: Requires Windows XP Professional, Windows 2000 Professional, or Windows NT Workstation 4.0.

Server: Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.

Product: IIS

See Also