Re: Passing in SqlConnection by ref

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 02/13/05


Date: Sun, 13 Feb 2005 19:16:51 -0000

LP <lp@a.com> wrote:
> Craig, Now, that's what I call a good explanation. Thanks a lot.
>
> My concern was if I pass in connection to another method, I wanted to make
> sure that both objects will be working with same instance of connection
> object. So it can closed/disposed in one place. I thought I needed to pass
> it in with "ref" to accomplish that.
> From what you're saying as long as I don't create a new instance in a
> receiving method, it will be the same instance of conn object, since it's a
> reference type. So "ref" is not really required, though it would more or
> less do the same thing (it's a true pointer as oppose to reference type).
> Please let me know if my interpretations are correct.

That sounds about right. Don't use ref unless you need to though - it
would suggest to someone reading the code that you were going to change
the value of the variable within the method.

-- 
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Relevant Pages

  • Re: Tech building
    ... That's why I explained about the connection between states in my other ... doubts as to whether the "symbol grounding problem" (if you want to ... And then you point to LEDs as requiring a QM explanation for how they ... I feel as if I'm in the position of explaining why aluminium oxide is ...
    (rec.arts.sf.composition)
  • Re: Passing in SqlConnection by ref
    ... > Craig, Now, that's what I call a good explanation. ... > My concern was if I pass in connection to another method, ... > Please let me know if my interpretations are correct. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Vista Myths
    ... >>> What possible explanation would I need? ... >> you need some explanation because the REALITY is that my video footage ... >> be the one having a problem accepting reality. ... network connection, ...
    (comp.sys.mac.advocacy)
  • Re: Michael Jacksons dead
    ... If you have a better explanation for why thousands of people are going to send flowers to his grave, ... people extend their connection to the artist when they feel connected to the art itself. ... Glenn Miller we a real musician, ... I am very unhappy with how youth culture turned out right now. ...
    (alt.guitar.bass)
  • Re: Cant connect to instance name - need explaination rather than ans
    ... an explanation of connecting to named instances: ... SQL Server Resolution Service to find what port number ... that's one of the primary connection ...
    (microsoft.public.sqlserver.connect)