ASP Collections
Collectionsen innehåller alla objekt som har lagts till i application/session via skriptkommandon.
Tips:För att ta bort projekt från Collectionsen, använd metoder som Remove och RemoveAll.
Syntaks
Application.Contents(Nyckel) Session.Contents(Nyckel)
Parameter | Beskrivning |
---|---|
nyckel | Obligatorisk. Namnet på projektet som ska hämtas. |
För Application-objektet
Exempel 1
Observera att name och objtest kommer att läggas till i Collectionsen:
<% Application("name")="W3School" Set Application("objtest")=Server.CreateObject("ADODB.Connection") %>
Exempel 2
Genomgå Collectionsen:
<% for each x in Application.Contents Response.Write(x & "=" & Application.Contents(x) & "<br />") nästa %>
Eller:
<% For i=1 to Application.Contents.Count Response.Write(i & "=" & Application.Contents(i) & "<br />") Nästa %>
Exempel 3
<% Application("date")="2001/05/05" Application("author")="W3School" for each x in Application.Contents Response.Write(x & "=" & Application.Contents(x) & "<br />") nästa %>
Uttal:
date=2001/05/05 author=W3School
För Session-objektet
Exempel 1
Observera att name och objtest kommer att läggas till i Collectionsen:
<% Session("name")="Hege" Set Session("objtest")=Server.CreateObject("ADODB.Connection") %>
Exempel 2
Genomgå Collectionsen:
<% för varje x i Session.Contents Response.Write(x & "=" & Session.Contents(x) & "<br />") nästa %>
Eller:
<% For i=1 to Session.Contents.Count Response.Write(i & "=" & Session.Contents(i) & "<br />") Nästa %>
Exempel 3
<% Session("name")="Hege" Session("date")="2001/05/05" för varje x i Session.Contents Response.Write(x & "=" & Session.Contents(x) & "<br />") nästa %>
Uttal:
name=Hege date=2001/05/05