gpt4 book ai didi

c# - Session.Add ("key",value) 和 Session ["key"] = value 之间有什么区别?

转载 作者:IT王子 更新时间:2023-10-29 04:19:00 25 4
gpt4 key购买 nike

谁能给我解释一下:

Session.Add("name",txtName.text);Session["name"] = txtName.text;

这是一个面试问题,我回答说两者都以 key = "Value" 格式存储数据,就像 C# 中的 Dictionary 类。

我说的对吗,有什么不同吗?

最佳答案

查看 HttpSessionState 的代码向我们表明它们实际上是相同的。

public sealed class HttpSessionState : ICollection, IEnumerable
{
private IHttpSessionState _container;
...
public void Add(string name, object value)
{
this._container[name] = value;
}

public object this[string name]
{
get
{
return this._container[name];
}
set
{
this._container[name] = value;
}
}
...
}

至于他们俩

Storing data in key = "Value" format like Dictionary class in C#.

它们实际上将结果存储在 IHttpSessionState 对象中。

关于c# - Session.Add ("key",value) 和 Session ["key"] = value 之间有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10017962/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com