SessionStateItemCollection 类

定义

存储在会话状态中的对象的集合。 此类不能被继承。

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
继承
SessionStateItemCollection
实现

示例

下面的代码示例创建一个新 SessionStateItemCollection 对象并设置并按名称获取集合中的值。

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 类用于管理由变量名称或数值索引编制索引的会话状态变量值。 会话状态变量使用HttpSessionState类向 ASP.NET 应用程序代码公开,该类是使用Session当前或属性HttpContext访问的Page。 The HttpSessionState class calls the HttpSessionStateContainer class, which manages session-state variable values using the SessionStateItemCollection.

继承者说明

基于 SessionStateStoreProviderBase 类创建自定义会话状态提供程序时,请使用 SessionStateItemCollection 该类来管理存储在会话状态中的项。 如果需要创建自定义对象来管理会话状态项,请实现 ISessionStateItemCollection 接口。

构造函数

SessionStateItemCollection()

创建一个新的空 SessionStateItemCollection 对象。

属性

Count

获取包含在 NameObjectCollectionBase 实例中的键/值对的数目。

(继承自 NameObjectCollectionBase)
Dirty

获取或设置一个值,该值指示是否已将集合标记为“已更改”。

IsReadOnly

获取或设置一个值,通过该值指示 NameObjectCollectionBase 实例是否为只读的。

(继承自 NameObjectCollectionBase)
Item[Int32]

按照数字索引获取或设置集合中的值。

Item[String]

按名称获取或设置集合中的值。

Keys

为存储在集合中的所有值获取变量名的集合。

方法

BaseAdd(String, Object)

将具有指定键和值的项添加到 NameObjectCollectionBase 实例中。

(继承自 NameObjectCollectionBase)
BaseClear()

移除 NameObjectCollectionBase 实例中的所有项。

(继承自 NameObjectCollectionBase)
BaseGet(Int32)

获取 NameObjectCollectionBase 实例的指定索引处的项值。

(继承自 NameObjectCollectionBase)
BaseGet(String)

获取 NameObjectCollectionBase 实例中第一个具有指定键的项值。

(继承自 NameObjectCollectionBase)
BaseGetAllKeys()

返回 String 数组,该数组包含 NameObjectCollectionBase 实例中的所有键。

(继承自 NameObjectCollectionBase)
BaseGetAllValues()

返回 Object 数组,该数组包含 NameObjectCollectionBase 实例中的所有值。

(继承自 NameObjectCollectionBase)
BaseGetAllValues(Type)

返回指定类型的数组,该数组包含 NameObjectCollectionBase 实例中的所有值。

(继承自 NameObjectCollectionBase)
BaseGetKey(Int32)

获取 NameObjectCollectionBase 实例的指定索引处的项键。

(继承自 NameObjectCollectionBase)
BaseHasKeys()

获取一个值,通过该值指示 NameObjectCollectionBase 实例是否包含键不为 null 的项。

(继承自 NameObjectCollectionBase)
BaseRemove(String)

移除 NameObjectCollectionBase 实例中具有指定键的项。

(继承自 NameObjectCollectionBase)
BaseRemoveAt(Int32)

移除 NameObjectCollectionBase 实例的指定索引处的项。

(继承自 NameObjectCollectionBase)
BaseSet(Int32, Object)

设置 NameObjectCollectionBase 实例的指定索引处的项值。

(继承自 NameObjectCollectionBase)
BaseSet(String, Object)

NameObjectCollectionBase 实例中第一个具有指定键的项设置值(如果有这样的项);否则将具有指定键和值的项添加到 NameObjectCollectionBase 实例中。

(继承自 NameObjectCollectionBase)
Clear()

从会话状态集合中移除所有的值和键。

Deserialize(BinaryReader)

使用 SessionStateItemCollection 方法在要写入的存储位置创建一个 Serialize(BinaryWriter) 集合。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetEnumerator()

返回一个枚举数,它可以用来读取集合中的所有键名。

GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetObjectData(SerializationInfo, StreamingContext)

实现 ISerializable 接口,并返回序列化 NameObjectCollectionBase 实例所需的数据。

(继承自 NameObjectCollectionBase)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
OnDeserialization(Object)

实现 ISerializable 接口,并在完成反序列化之后引发反序列化事件。

(继承自 NameObjectCollectionBase)
Remove(String)

从集合中删除某个项。

RemoveAt(Int32)

删除集合中指定索引处的项。

Serialize(BinaryWriter)

将集合的内容写入 BinaryWriter

ToString()

返回表示当前对象的字符串。

(继承自 Object)

显式接口实现

ICollection.CopyTo(Array, Int32)

从目标数组的指定索引处开始将整个 NameObjectCollectionBase 复制到兼容的一维 Array

(继承自 NameObjectCollectionBase)
ICollection.IsSynchronized

获取一个值,该值指示对 NameObjectCollectionBase 对象的访问是否同步(线程安全)。

(继承自 NameObjectCollectionBase)
ICollection.SyncRoot

获取一个对象,该对象可用于同步对 NameObjectCollectionBase 对象的访问。

(继承自 NameObjectCollectionBase)

扩展方法

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。

AsParallel(IEnumerable)

启用查询的并行化。

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryable

适用于

另请参阅