我们的代码有时会从函数返回一个SPWeb对象。举个例子:
public SPWeb getDeptWeb()
{
SPWeb deptWeb = SpSite.OpenWeb(SpContext.Web.ID);
...
return deptWeb;
}在这种情况下,我们如何处理SPWeb对象呢?或者在我们接受返回参数的地方处理它就足够了吗?
发布于 2010-12-07 17:27:49
最好的方法可能是在调用方中处理SPWeb,例如使用using语句:
public SPWeb getDeptWeb()
{
SPWeb deptWeb = SpSite.OpenWeb(SpContext.Web.ID);
// ...
return deptWeb;
}
public void Foo()
{
using (SPWeb deptWeb = getDeptWeb()) {
// Do something with the website...
}
}https://stackoverflow.com/questions/4375038
复制相似问题