本文介绍了配置在C#,点网框架中的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类型1:

objMortgageBAL = new MortgageBAL();
                int Result = objMortgageBAL.SaveLegalTeamComments(CauseNo, DefendantID);




类型2:




Type 2:

int Result = new MortgageBAL().SaveLegalTeamComments(CauseNo, DefendantID);



我在我的项目中使用了上面提到的两种类型的代码.什么时候将"MortgageBAL()"对象放置在Type2中?



i have used code in my project as mentioned both types above. When will "MortgageBAL()" object will dispose in Type2? Which one is good coding practice?

推荐答案

using (objMortgageBAL = new MortgageBAL())
   {
   int Result = objMortgageBAL.SaveLegalTeamComments(CauseNo, DefendantID);
   ...
   }

在这种情况下,当MortgageBAL对象超出范围时,将在右花括号处对其进行处理.

In which case the MortgageBAL object will be disposed when it goes out of scope at the closing curly bracket.


这篇关于配置在C#,点网框架中的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 01:56