本文介绍了通过ref传入SqlConnection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 你好, 这里是场景: 对象A打开一个Sql Db连接来执行多个SqlCommands。然后它需要将这个连接传递给对象B的构造函数,而对象B的构造函数又会在同一个连接上执行更多命令。 我有要理解如果SqlConnection作为value传递给(unboxed),对象B将创建自己的SqlConnection副本,所以当 对象A关闭其连接时,对于对象B'的副本,它仍然是开放的。这是 是否正确?是不是通过ref传递它的正确方法?什么是最好的 做法? 谢谢。 Hello, Here''s the scenario: Object A opens a Sql Db connection to execute number of SqlCommands. Then itneeds to pass this connection to a constructor of object B which in turnexecutes more commands on the same connection.I have an understanding that if SqlConnection is passed as "value"(unboxed), object B will create its own copy of SqlConnection, so whenobject A closes its connection, it remains open for object B''s copy. Is thiscorrect? Is not the right way to pass it by ref? What are "the bestpractices"? Thank you.推荐答案 这篇关于通过ref传入SqlConnection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-19 17:22