谁能给我解释一下:
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 likeDictionary
class in C#.
它们实际上将结果存储在 IHttpSessionState
对象中。
关于c# - Session.Add ("key",value) 和 Session ["key"] = value 之间有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10017962/