SessionStateItemCollection SessionStateItemCollection SessionStateItemCollection SessionStateItemCollection Class

定义

存储在会话状态中的对象的集合。A collection of objects stored in session state. 此类不能被继承。This class cannot be inherited.

public ref class SessionStateItemCollection sealed : System::Collections::Specialized::NameObjectCollectionBase, System::Collections::ICollection, System::Web::SessionState::ISessionStateItemCollection
public sealed class SessionStateItemCollection : System.Collections.Specialized.NameObjectCollectionBase, System.Collections.ICollection, System.Web.SessionState.ISessionStateItemCollection
type SessionStateItemCollection = class
    inherit NameObjectCollectionBase
    interface ISessionStateItemCollection
    interface ICollection
    interface IEnumerable
Public NotInheritable Class SessionStateItemCollection
Inherits NameObjectCollectionBase
Implements ICollection, ISessionStateItemCollection
继承
SessionStateItemCollectionSessionStateItemCollectionSessionStateItemCollectionSessionStateItemCollection
实现

示例

下面的代码示例创建一个新SessionStateItemCollection的对象, 并按名称设置和获取集合中的值。The following code example creates a new SessionStateItemCollection object and sets and gets values in the collection by name.

SessionStateItemCollection items = new SessionStateItemCollection();

items["LastName"] = "Wilson";
items["FirstName"] = "Dan";

foreach (string s in items.Keys)
  Response.Write("items[\"" + s + "\"] = " + items[s].ToString() + "<br />");
Dim items As SessionStateItemCollection = New SessionStateItemCollection()

items("LastName") = "Wilson"
items("FirstName") = "Dan"

For Each s As String In items.Keys
  Response.Write("items(""" & s & """) = " & items(s).ToString() & "<br />")
Next

注解

SessionStateItemCollection类用于管理按变量名称或数字索引编制索引的会话状态变量值。The SessionStateItemCollection class is used to manage session-state variable values indexed by a variable name or by numerical index. 会话HttpSessionState状态变量使用类公开给 ASP.NET 应用程序代码, 该类可Session使用当前HttpContextPage的属性访问。The session-state variables are exposed to ASP.NET application code using the HttpSessionState class, which is accessed using the Session property of the current HttpContext or the Page. 类调用类, 该类使用来管理会话SessionStateItemCollection状态变量值。 HttpSessionStateContainer HttpSessionStateThe HttpSessionState class calls the HttpSessionStateContainer class, which manages session-state variable values using the SessionStateItemCollection.

继承者说明

创建基于类的SessionStateStoreProviderBase自定义会话状态提供程序时, 请SessionStateItemCollection使用类管理会话状态中存储的项。When you create a custom session-state provider based on the SessionStateStoreProviderBase class, use the SessionStateItemCollection class to manage the items stored in session state. 如果需要创建自定义对象来管理会话状态项, 请实现ISessionStateItemCollection接口。If you need to create a custom object to manage session-state items, implement the ISessionStateItemCollection interface.

构造函数

SessionStateItemCollection() SessionStateItemCollection() SessionStateItemCollection() SessionStateItemCollection()

创建一个新的空 SessionStateItemCollection 对象。Creates a new, empty SessionStateItemCollection object.

属性

Count Count Count Count

获取包含在 NameObjectCollectionBase 实例中的键/值对的数目。Gets the number of key/value pairs contained in the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
Dirty Dirty Dirty Dirty

获取或设置一个值,该值指示是否已将集合标记为“已更改”。Gets or sets a value indicating whether the collection has been marked as changed.

ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized

获取一个值,该值指示对 NameObjectCollectionBase 对象的访问是否同步(线程安全)。Gets a value indicating whether access to the NameObjectCollectionBase object is synchronized (thread safe).

(Inherited from NameObjectCollectionBase)
ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot

获取一个对象,该对象可用于同步对 NameObjectCollectionBase 对象的访问。Gets an object that can be used to synchronize access to the NameObjectCollectionBase object.

(Inherited from NameObjectCollectionBase)
IsReadOnly IsReadOnly IsReadOnly IsReadOnly

获取或设置一个值,通过该值指示 NameObjectCollectionBase 实例是否为只读的。Gets or sets a value indicating whether the NameObjectCollectionBase instance is read-only.

(Inherited from NameObjectCollectionBase)
Item[Int32] Item[Int32] Item[Int32] Item[Int32]

按照数字索引获取或设置集合中的值。Gets or sets a value in the collection by numerical index.

Item[String] Item[String] Item[String] Item[String]

按名称获取或设置集合中的值。Gets or sets a value in the collection by name.

Keys Keys Keys Keys

为存储在集合中的所有值获取变量名的集合。Gets a collection of the variable names for all values stored in the collection.

方法

BaseAdd(String, Object) BaseAdd(String, Object) BaseAdd(String, Object) BaseAdd(String, Object)

将具有指定键和值的项添加到 NameObjectCollectionBase 实例中。Adds an entry with the specified key and value into the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseClear() BaseClear() BaseClear() BaseClear()

移除 NameObjectCollectionBase 实例中的所有项。Removes all entries from the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseGet(Int32) BaseGet(Int32) BaseGet(Int32) BaseGet(Int32)

获取 NameObjectCollectionBase 实例的指定索引处的项值。Gets the value of the entry at the specified index of the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseGet(String) BaseGet(String) BaseGet(String) BaseGet(String)

获取 NameObjectCollectionBase 实例中第一个具有指定键的项值。Gets the value of the first entry with the specified key from the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseGetAllKeys() BaseGetAllKeys() BaseGetAllKeys() BaseGetAllKeys()

返回 String 数组,该数组包含 NameObjectCollectionBase 实例中的所有键。Returns a String array that contains all the keys in the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseGetAllValues() BaseGetAllValues() BaseGetAllValues() BaseGetAllValues()

返回 Object 数组,该数组包含 NameObjectCollectionBase 实例中的所有值。Returns an Object array that contains all the values in the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseGetAllValues(Type) BaseGetAllValues(Type) BaseGetAllValues(Type) BaseGetAllValues(Type)

返回指定类型的数组,该数组包含 NameObjectCollectionBase 实例中的所有值。Returns an array of the specified type that contains all the values in the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseGetKey(Int32) BaseGetKey(Int32) BaseGetKey(Int32) BaseGetKey(Int32)

获取 NameObjectCollectionBase 实例的指定索引处的项键。Gets the key of the entry at the specified index of the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseHasKeys() BaseHasKeys() BaseHasKeys() BaseHasKeys()

获取一个值,通过该值指示 NameObjectCollectionBase 实例是否包含键不为 null 的项。Gets a value indicating whether the NameObjectCollectionBase instance contains entries whose keys are not null.

(Inherited from NameObjectCollectionBase)
BaseRemove(String) BaseRemove(String) BaseRemove(String) BaseRemove(String)

移除 NameObjectCollectionBase 实例中具有指定键的项。Removes the entries with the specified key from the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseRemoveAt(Int32) BaseRemoveAt(Int32) BaseRemoveAt(Int32) BaseRemoveAt(Int32)

移除 NameObjectCollectionBase 实例的指定索引处的项。Removes the entry at the specified index of the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseSet(Int32, Object) BaseSet(Int32, Object) BaseSet(Int32, Object) BaseSet(Int32, Object)

设置 NameObjectCollectionBase 实例的指定索引处的项值。Sets the value of the entry at the specified index of the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseSet(String, Object) BaseSet(String, Object) BaseSet(String, Object) BaseSet(String, Object)

NameObjectCollectionBase 实例中第一个具有指定键的项设置值(如果有这样的项);否则将具有指定键和值的项添加到 NameObjectCollectionBase 实例中。Sets the value of the first entry with the specified key in the NameObjectCollectionBase instance, if found; otherwise, adds an entry with the specified key and value into the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
Clear() Clear() Clear() Clear()

从会话状态集合中移除所有的值和键。Removes all values and keys from the session-state collection.

Deserialize(BinaryReader) Deserialize(BinaryReader) Deserialize(BinaryReader) Deserialize(BinaryReader)

使用 SessionStateItemCollection 方法在要写入的存储位置创建一个 Serialize(BinaryWriter) 集合。Creates a SessionStateItemCollection collection from a storage location that is written to using the Serialize(BinaryWriter) method.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

返回一个枚举数,它可以用来读取集合中的所有键名。Returns an enumerator that can be used to read all the key names in the collection.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext)

实现 ISerializable 接口,并返回序列化 NameObjectCollectionBase 实例所需的数据。Implements the ISerializable interface and returns the data needed to serialize the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
OnDeserialization(Object) OnDeserialization(Object) OnDeserialization(Object) OnDeserialization(Object)

实现 ISerializable 接口,并在完成反序列化之后引发反序列化事件。Implements the ISerializable interface and raises the deserialization event when the deserialization is complete.

(Inherited from NameObjectCollectionBase)
Remove(String) Remove(String) Remove(String) Remove(String)

从集合中删除某个项。Deletes an item from the collection.

RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32)

删除集合中指定索引处的项。Deletes an item at a specified index from the collection.

Serialize(BinaryWriter) Serialize(BinaryWriter) Serialize(BinaryWriter) Serialize(BinaryWriter)

将集合的内容写入 BinaryWriterWrites the contents of the collection to a BinaryWriter.

ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

显式界面实现

ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32)

从目标数组的指定索引处开始将整个 NameObjectCollectionBase 复制到兼容的一维 ArrayCopies the entire NameObjectCollectionBase to a compatible one-dimensional Array, starting at the specified index of the target array.

(Inherited from NameObjectCollectionBase)

扩展方法

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

适用于

另请参阅